Skip to content

Commit

Permalink
allow parallel envs with cucumber (#4095)
Browse files Browse the repository at this point in the history

---------

Co-authored-by: Priyansh Garg <priyanshgarg30@gmail.com>
  • Loading branch information
AutomatedTester and garg3133 committed Mar 15, 2024
1 parent a13f7dd commit 904d0f8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 10 deletions.
10 changes: 7 additions & 3 deletions lib/runner/cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ class CliRunner {

if (plugins.length > 0) {
plugins.forEach((plugin) => {
if (plugin.globals && Utils.isFunction(plugin.globals.registerEventHandlers)){
if (plugin.globals && Utils.isFunction(plugin.globals.registerEventHandlers)) {
plugin.globals.registerEventHandlers(NightwatchEventHub);
}
});
Expand Down Expand Up @@ -450,7 +450,11 @@ class CliRunner {
}

isTestWorkersEnabled() {
const testWorkers = this.test_settings.testWorkersEnabled && !singleSourceFile(this.argv);
if (this.testRunner.supportsParallelTestSuiteRun === false) {
return false;
}

const testWorkers = this.test_settings.testWorkersEnabled && !singleSourceFile(this.argv);
if (!testWorkers) {

if (this.argv.debug) {
Expand All @@ -466,7 +470,7 @@ class CliRunner {

if (isMobile(desiredCapabilities) && !this.usingServer(this.testEnvSettings[env])) {

if (Concurrency.isWorker()) {
if (Concurrency.isWorker()) {
Logger.info('Disabling parallelism while running tests on mobile platform');
}

Expand Down
4 changes: 4 additions & 0 deletions lib/runner/test-runners/cucumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ class CucumberSuite extends TestSuite {

class CucumberRunnner extends Runner {
get supportsConcurrency() {
return true;
}

get supportsParallelTestSuiteRun() {
return false;
}

Expand Down
45 changes: 39 additions & 6 deletions test/cucumber-integration-tests/testCucumberTestsInParallel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ const commandMocks = require('../lib/command-mocks.js');
const common = require('../common.js');
const MockServer = require('../lib/mockserver.js');

describe('Cucumber integration - parallel running single formatter', function() {
beforeEach(function(done) {
describe('Cucumber integration - parallel running single formatter', function () {
beforeEach(function (done) {
this.server = MockServer.init(null, {port: 10190});
this.server.on('listening', () => done());
});

afterEach(function(done) {
afterEach(function (done) {
Globals.afterEach.call(this, done);
});

it('testCucumberSampleTests in parallel with single formatter', function() {
it('testCucumberSampleTests in parallel with single formatter', function () {
const source = [
path.join(__dirname, './sample_cucumber_tests/parallel/testSample.js')
];
Expand All @@ -41,7 +41,7 @@ describe('Cucumber integration - parallel running single formatter', function()
});
});

it('testCucumberSampleTests in parallel with multiple step definition files', function() {
it('testCucumberSampleTests in parallel with multiple step definition files', function () {

commandMocks.elementText('5cc459b8-36a8-3042-8b4a-258883ea642b', 'xx');

Expand All @@ -56,6 +56,7 @@ describe('Cucumber integration - parallel running single formatter', function()
parallel: true,
verbose: true,
timeout: 10,
env: 'chrome',
silent: false,
tags: ['not @fail'],
format: 'progress',
Expand All @@ -71,4 +72,36 @@ describe('Cucumber integration - parallel running single formatter', function()
assert.strictEqual(errorOrFailed, false);
});
});
});

it('testCucumberSampleTests in parallel environments with multiple step definition files', function () {

commandMocks.elementText('5cc459b8-36a8-3042-8b4a-258883ea642b', 'xx');

const source = [
path.join(__dirname, './sample_cucumber_tests/parallelWithMultipleDefinition')
];

const {runTests} = common.require('index.js');

return runTests({
source,
parallel: true,
verbose: true,
timeout: 10,
env: 'chrome,firefox',
silent: false,
tags: ['not @fail'],
format: 'progress',
config: path.join(__dirname, '../extra/cucumber-config-parallel.js'),
'format-options': '',
['retry-interval']: 5,
['persist-globals']: true,
['webdriver-host']: 'localhost',
['start-process']: false,
['webdriver-port']: 10190
}, {})
.then(errorOrFailed => {
assert.strictEqual(errorOrFailed, false);
});
});
});
15 changes: 14 additions & 1 deletion test/extra/cucumber-config-parallel.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ module.exports = {
feature_path: path.join(__dirname, '../cucumber-integration-tests/sample_cucumber_tests/parallel/sample.feature')
}
},

test_settings: {
chrome: {
desiredCapabilities: {
browserName: 'chrome'
}
},
firefox: {
desiredCapabilities: {
browserName: 'firefox'
}
}
},
output: false,
silent: false
}
};

0 comments on commit 904d0f8

Please sign in to comment.