Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes/3431 consider always match from desired capabilities #3907

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions lib/runner/cli/nightwatch.conf.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,12 @@ module.exports = {
firefox: {
desiredCapabilities : {
browserName : 'firefox',
alwaysMatch: {
acceptInsecureCerts: true,
'moz:firefoxOptions': {
args: [
// '-headless',
// '-verbose'
]
}
acceptInsecureCerts: true,
'moz:firefoxOptions': {
args: [
// '-headless',
// '-verbose'
]
}
},
webdriver: {
Expand Down
14 changes: 9 additions & 5 deletions lib/transport/selenium-webdriver/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ module.exports = class SeleniumCapabilities {
createDesired() {
this.desiredCapabilities = this.settings.capabilities || this.settings.desiredCapabilities;

// flatten alwaysMatch param from desired Capabilities
Object.assign(this.desiredCapabilities, this.desiredCapabilities?.alwaysMatch);
delete this.desiredCapabilities['alwaysMatch'];

if (typeof this.desiredCapabilities == 'function') {
this.desiredCapabilities = this.desiredCapabilities.call(this.settings);
}
Expand Down Expand Up @@ -120,7 +124,7 @@ module.exports = class SeleniumCapabilities {
}

const {webdriver} = this.settings;
let options = new ChromeOptions(this.desiredCapabilities);
const options = new ChromeOptions(this.desiredCapabilities);

if (webdriver.chrome_binary || this.settings.chrome_binary) {
options.setChromeBinaryPath(webdriver.chrome_binary || this.settings.chrome_binary);
Expand All @@ -145,7 +149,7 @@ module.exports = class SeleniumCapabilities {
}

const {webdriver} = this.settings;
let options = new IeOptions(this.desiredCapabilities);
const options = new IeOptions(this.desiredCapabilities);

if (webdriver.log_path || this.settings.log_path) {
options.setLogFile(webdriver.log_path || this.settings.log_path);
Expand All @@ -166,7 +170,7 @@ module.exports = class SeleniumCapabilities {
}

const {webdriver} = this.settings;
let options = new EdgeOptions(this.desiredCapabilities);
const options = new EdgeOptions(this.desiredCapabilities);

if (webdriver.edge_binary || this.settings.edge_binary) {
options.setEdgeChromiumBinaryPath(webdriver.edge_binary || this.settings.edge_binary);
Expand Down Expand Up @@ -194,7 +198,7 @@ module.exports = class SeleniumCapabilities {
}

const {webdriver} = this.settings;
let options = new FirefoxOptions(this.desiredCapabilities);
const options = new FirefoxOptions(this.desiredCapabilities);

if (webdriver.firefox_binary || this.settings.firefox_binary) {
options.setBinary(webdriver.firefox_binary || this.settings.firefox_binary);
Expand All @@ -214,7 +218,7 @@ module.exports = class SeleniumCapabilities {
return this.desiredCapabilities;
}

let options = new SafariOptions(this.desiredCapabilities);
const options = new SafariOptions(this.desiredCapabilities);

return options;
}
Expand Down
8 changes: 3 additions & 5 deletions test/src/cli/testCliRunnerGenerate.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,9 @@ describe('Test CLI Runner Generate', function() {
assert.deepStrictEqual(configData.test_settings.firefox, {
desiredCapabilities: {
browserName: 'firefox',
alwaysMatch: {
acceptInsecureCerts: true,
'moz:firefoxOptions': {
args: []
}
acceptInsecureCerts: true,
'moz:firefoxOptions': {
args: []
}
},
webdriver: {
Expand Down
24 changes: 24 additions & 0 deletions test/src/index/transport/testChromeOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,28 @@ describe('Test chrome options', function () {
});
});

it('always match in desired capabilties', function() {
const client = Nightwatch.createClient({
desiredCapabilities: {
browserName: 'chrome',
alwaysMatch: {
acceptInsecureCerts: true,
'goog:chromeOptions': {
args: [
'--headless'
]
}
}
}
});

const options = client.transport.createSessionOptions();
assert.ok(options instanceof ChromeOptions);
assert.strictEqual(options.get('acceptInsecureCerts'), true);
assert.deepStrictEqual(options.get('goog:chromeOptions'), {
args: ['--headless']
});
});


});
23 changes: 23 additions & 0 deletions test/src/index/transport/testFirefoxOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,27 @@ describe('Firefox driver options', function(){
});
});

it('always match in desired capabilties', function() {
const client = Nightwatch.createClient({
desiredCapabilities: {
desiredCapabilities: 'firefox',
alwaysMatch: {
acceptInsecureCerts: true,
'moz:firefoxOptions': {
args: [
'--headless'
]
}
}
}
});

const options = client.transport.createSessionOptions();
assert.ok(options instanceof FirefoxOptions);
assert.strictEqual(options.get('acceptInsecureCerts'), true);
assert.deepStrictEqual(options.get('moz:firefoxOptions'), {
args: ['--headless']
});
});

});
Loading