From fcd607a93412394a70ea2cb8ba4cc220e2d9f5cf Mon Sep 17 00:00:00 2001 From: Ravi Sawlani Date: Wed, 6 Sep 2023 01:26:52 +0530 Subject: [PATCH 1/4] consider alwaysMatch params from desiredCapabilities --- lib/transport/selenium-webdriver/options.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/transport/selenium-webdriver/options.js b/lib/transport/selenium-webdriver/options.js index c7c853c59c..e17f1ef328 100644 --- a/lib/transport/selenium-webdriver/options.js +++ b/lib/transport/selenium-webdriver/options.js @@ -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); } @@ -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); @@ -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); @@ -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); @@ -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); @@ -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; } From 5b3fd35d6a4642afd65cd7ceec7f7cc1157c381b Mon Sep 17 00:00:00 2001 From: Ravi Sawlani Date: Wed, 6 Sep 2023 01:27:34 +0530 Subject: [PATCH 2/4] modify nightwatch default config --- lib/runner/cli/nightwatch.conf.ejs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/runner/cli/nightwatch.conf.ejs b/lib/runner/cli/nightwatch.conf.ejs index 4f3501a3f0..b45f789912 100644 --- a/lib/runner/cli/nightwatch.conf.ejs +++ b/lib/runner/cli/nightwatch.conf.ejs @@ -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: { From f1ef8ae30a74275aa4d345e16ca3fe7df982a2bb Mon Sep 17 00:00:00 2001 From: Ravi Sawlani Date: Wed, 6 Sep 2023 01:30:08 +0530 Subject: [PATCH 3/4] added test --- test/src/index/transport/testChromeOptions.js | 24 +++++++++++++++++++ .../src/index/transport/testFirefoxOptions.js | 23 ++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/test/src/index/transport/testChromeOptions.js b/test/src/index/transport/testChromeOptions.js index d61856c85a..e3982eb775 100644 --- a/test/src/index/transport/testChromeOptions.js +++ b/test/src/index/transport/testChromeOptions.js @@ -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'] + }); + }); + + }); diff --git a/test/src/index/transport/testFirefoxOptions.js b/test/src/index/transport/testFirefoxOptions.js index 9493777fde..41c6890a04 100644 --- a/test/src/index/transport/testFirefoxOptions.js +++ b/test/src/index/transport/testFirefoxOptions.js @@ -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'] + }); + }); + }); From de832d186c8de7ffc5d3c48c5f9b06db21400e86 Mon Sep 17 00:00:00 2001 From: Ravi Sawlani Date: Tue, 26 Sep 2023 15:27:30 +0530 Subject: [PATCH 4/4] fix cli runner generate test --- test/src/cli/testCliRunnerGenerate.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/src/cli/testCliRunnerGenerate.js b/test/src/cli/testCliRunnerGenerate.js index 862965ff2c..8e6f4f559f 100644 --- a/test/src/cli/testCliRunnerGenerate.js +++ b/test/src/cli/testCliRunnerGenerate.js @@ -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: {