Skip to content

Commit

Permalink
added more tests for describe interface
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed Oct 24, 2019
1 parent 47e4dd1 commit 51a34ed
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 7 deletions.
9 changes: 5 additions & 4 deletions lib/testsuite/testsuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,17 +274,18 @@ class TestSuite {
return failures;
})
.then(async (failures) => {
let testFailed = failures || !this.reporter.allTestsPassed;
try {
await this.terminate(failures ? 'FAILED' : '')
await this.terminate(testFailed ? 'FAILED' : '')
} catch (err) {
Logger.error(`Could not stop session in ${this.suiteName}:`);
Logger.error(err);
}

return failures || !this.reporter.allTestsPassed;
return testFailed;
})
.then(failures => {
return this.testSuiteFinished(failures);
.then(testFailed => {
return this.testSuiteFinished(testFailed);
});

}
Expand Down
30 changes: 30 additions & 0 deletions test/sampletests/withdescribe/basic/sampleWithOnly.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
describe('basic describe test', function () {

this.desiredCapabilities = {
name: 'basicDescribe'
};

this.timeout(55);
this.tags = ['something'];
this.endSessionOnFail = false;
this.skipTestcasesOnFail = false;

test('demoTest one', function (client) {
client.url('http://localhost')
.assert.elementPresent('#weblogin');
});

test.only('demoTest two', function (client) {
client.assert.strictEqual(client.options.globals.waitForConditionTimeout, 55);
client.assert.strictEqual(this.settings.desiredCapabilities.name, 'basicDescribe');

client.url('http://localhost')
.assert.elementPresent('#weblogin');
});

test('demoTest three', function (client) {
client.url('http://localhost')
.assert.elementPresent('#weblogin');
});
});

37 changes: 37 additions & 0 deletions test/sampletests/withdescribe/failures/sampleSkipTestcases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
describe('sample test with skipTestcasesOnFail', function() {
this.skipTestcasesOnFail = false;
this.endSessionOnFail = false;
this.timeout(10);

let endFn;

before(function(client, done) {
endFn = client.end;
done();
});

it('demoTest', function (client) {
client.globals.calls++;

client.url('http://localhost')
.assert.elementPresent('#weblogin')
.assert.elementPresent('#badElement');
});

it('demoTest2', function (client) {
client.globals.calls++;

client.end = function() {
client.assert.fail('End should not be called.')
};

client.url('http://localhost')
.assert.elementPresent('#weblogin')
.assert.elementPresent('#badElement');
});

after(function(client, done) {
client.end = endFn;
done();
});
});
6 changes: 3 additions & 3 deletions test/src/runner/cli/testParallelExecution.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('test Parallel Execution', function() {
assert.ok(runner.test_settings.test_workers);

return runner.runTests().then(_ => {
assert.strictEqual(allArgs.length, 40);
assert.strictEqual(allArgs.length, 42);
assert.strictEqual(runner.concurrency.globalExitCode, 0);
});
});
Expand Down Expand Up @@ -134,7 +134,7 @@ describe('test Parallel Execution', function() {
});

return runner.runTests().then(_ => {
assert.strictEqual(allArgs.length, 40);
assert.strictEqual(allArgs.length, 42);
});
});

Expand Down Expand Up @@ -163,7 +163,7 @@ describe('test Parallel Execution', function() {
});

return runner.runTests().then(_ => {
assert.strictEqual(allArgs.length, 40);
assert.strictEqual(allArgs.length, 42);
});
});

Expand Down
63 changes: 63 additions & 0 deletions test/src/runner/testRunTestsuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,67 @@ describe('testRunTestSuite', function() {

return NightwatchClient.runTests(settings);
});

it('test runner with describe and .only()', function() {
let srcFolders = [
path.join(__dirname, '../../sampletests/withdescribe/basic/sampleWithOnly.js')
];

const settings = {
selenium: {
port: 10195,
version2: true,
start_process: true
},
globals: {
reporter(results, cb) {
if (results.lastError) {
throw results.lastError;
}

const testcases = results.modules.sampleWithOnly.completed;
assert.deepStrictEqual(Object.keys(testcases), ['demoTest two']);
cb();
}
},
silent: true,
output: false,
output_folder: false,
src_folders: srcFolders
};

return NightwatchClient.runTests(settings);
});

it('testRunner with describe and skipTestcasesOnFail=true', function() {
let testsPath = path.join(__dirname, '../../sampletests/withdescribe/failures/sampleSkipTestcases.js');
let globals = {
calls: 0,
retryAssertionTimeout: 0,
reporter(results, cb) {
assert.strictEqual(settings.globals.calls, 2);
assert.strictEqual(results.errors, 0);
assert.strictEqual(results.failed, 2);
cb();
}
};

const settings = {
selenium: {
port: 10195,
version2: true,
start_process: true
},
silent: false,
output: false,
persist_globals: true,
globals,
skip_testcases_on_fail: true,
output_folder: false,
};

return NightwatchClient.runTests({
_source: [testsPath]
}, settings);
});
});

0 comments on commit 51a34ed

Please sign in to comment.