Skip to content

Commit

Permalink
Fixes/consider test suite settings in cucumber runner (#3622)
Browse files Browse the repository at this point in the history
  • Loading branch information
gravityvi authored Feb 28, 2023
1 parent 2804577 commit f1411c1
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 2 deletions.
1 change: 1 addition & 0 deletions cucumber-js/_setup_cucumber_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Before(function({pickle}) {
webdriver,
persist_globals,
config: this.parameters.config,
test_settings: this.parameters.settings,
globals
});

Expand Down
8 changes: 7 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const {By, Key, Capabilities} = require('selenium-webdriver');
const lodashMerge = require('lodash.merge');
const Utils = require('./utils');
const Settings = require('./settings/settings.js');
const ElementGlobal = require('./api/_loaders/element-global.js');
Expand Down Expand Up @@ -40,7 +41,8 @@ module.exports.createClient = function({
devtools = false,
debug = false,
enable_global_apis = false,
config = './nightwatch.json'
config = './nightwatch.json',
test_settings
} = {}) {
if (browserName && !env) {
switch (browserName) {
Expand Down Expand Up @@ -102,6 +104,10 @@ module.exports.createClient = function({
});

cliRunner.test_settings.disable_global_apis = cliRunner.test_settings.disable_global_apis || !enable_global_apis;

//merge settings recieved from testsuite to cli runner settings (this might have changed in hooks)
lodashMerge(cliRunner.test_settings, test_settings);

const client = Nightwatch.client(cliRunner.test_settings, reporter, cliRunner.argv, true);

Object.defineProperty(Nightwatch, 'element', {
Expand Down
2 changes: 1 addition & 1 deletion lib/runner/test-runners/cucumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class CucumberSuite extends TestSuite {
const {feature_path = ''} = options;
const parallelArgs = this.usingCucumberWorkers ? ['--parallel', this.usingCucumberWorkers]: [];
const additionalOptions = this.buildArgvValue(['tags', 'retry-tag-filter', 'profile', 'format', 'format-options', 'dry-run', 'fail-fast', ['retry', 'retries'], 'no-strict', 'name']);
const extraParams = ['--world-parameters', JSON.stringify(this.argv)];
const extraParams = ['--world-parameters', JSON.stringify({...this.argv, settings: this.settings})];

return [
process.execPath,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
before(settings) {
settings.desiredCapabilities.browserName = 'chrome';
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const assert = require('assert');
const {Given, Then, After} = require('@cucumber/cucumber');

Given('I navigate to localhost', function() {
browser.globals.test_calls = 0;
browser.globals.test_calls++;

return browser.navigateTo('http://localhost');
});

Then('I check if webdriver is present', function() {
browser.globals.test_calls++;

return browser.assert.elementPresent('#webdriver');
});

Then('I check if webdriver is present and contains text', async function() {
browser.globals.test_calls++;

await browser.expect.element('#webdriver').text.to.contain('xx')
});

Then('I check if badElement is present', function() {
browser.globals.test_calls++;

return browser.assert.elementPresent('#badElement');
});

After(function() {
assert.strictEqual(browser.globals.test_calls, 2);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const path = require('path');
const assert = require('assert');
const Globals = require('../lib/globals/commands.js');
const common = require('../common.js');
const MockServer = require('../lib/mockserver.js');
const {runTests} = common.require('index.js');

describe('Cucumber integration - with modified settings in plugin', function() {
beforeEach(function(done) {
this.server = MockServer.init(null, {port: 10195});
this.server.on('listening', () => done());
});

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

it('testCucumberSampleTests with browsername modified (chrome) in plugin global hook', function() {
const source = [path.join(__dirname, './sample_cucumber_tests/with-modified-settings/testSample.js')];


const pluginPath = [path.join(__dirname, './sample_cucumber_tests/with-modified-settings/plugin')];

MockServer.addMock({
url: '/wd/hub/session',
method: 'POST',
statusCode: 201,
postdata: {
capabilities: {
firstMatch: [{}],
alwaysMatch: {browserName: 'chrome', 'goog:chromeOptions': {}}
}
},
response: {
status: 0,
sessionId: '1352110219202',
value: {browserName: 'chrome', browserVersion: 'TEST_chrome'},
state: null
}
}, true);


// modify browserName to chrome in plugin global hook
return runTests({
source,
tags: ['@pass'],
verbose: false,
config: path.join(__dirname, '../extra/cucumber-config.js')
}, {
plugins: pluginPath
})
.then(failures => {
assert.strictEqual(failures, false);
});
});

});

0 comments on commit f1411c1

Please sign in to comment.