Skip to content

Commit

Permalink
Fix - Issue #3625 - Changed to recursive merge on caps (#3831)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinodreddy-bs authored Jul 26, 2023
1 parent 2e0b867 commit adf2944
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/api/protocol/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = class Action extends ProtocolAction {

command(url, callback = function(r) {return r}) {
if (typeof url == 'string') {
let startTime = new Date();
const startTime = new Date();
let spinner;
if (this.settings.output) {
spinner = ora({
Expand Down
3 changes: 2 additions & 1 deletion lib/core/client.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const EventEmitter = require('events');
const {Key, Capabilities, Browser} = require('selenium-webdriver');

const lodashMerge = require('lodash/merge.js');
const HttpOptions = require('../http/options.js');
const HttpRequest = require('../http/request.js');
const Utils = require('../utils');
Expand Down Expand Up @@ -591,7 +592,7 @@ class NightwatchClient extends EventEmitter {
return;
}

Object.assign(this.initialCapabilities, props);
lodashMerge(this.initialCapabilities, props);
this.setSessionOptions();
}

Expand Down
63 changes: 63 additions & 0 deletions test/src/index/testProgrammaticApis.js
Original file line number Diff line number Diff line change
Expand Up @@ -795,4 +795,67 @@ describe('test programmatic apis', function () {
CliRunner.createDefaultConfig = createDefaultConfig;
CliRunner.prototype.loadConfig = loadConfig;
});

it('should test updateCapabilities() programmatic API with multiple nested caps', async function() {
const CliRunner = common.require('runner/cli/cli.js');
const Nightwatch = common.require('index.js');
MockServer.createFirefoxSession({});

const defaultConfig = {
test_settings: {
default: {
launchUrl: 'http://localhost'
}
},
selenium: {
port: 10195,
start_process: false
},
selenium_host: 'localhost'
};

const createDefaultConfig = CliRunner.createDefaultConfig;
const loadConfig = CliRunner.prototype.loadConfig;

CliRunner.createDefaultConfig = function(destFileName) {
return defaultConfig;
};

CliRunner.prototype.loadConfig = function () {
return defaultConfig;
};

const client = Nightwatch.createClient({
headless: true,
silent: false,
output: false,
enable_global_apis: true
});

client.updateCapabilities({
'testName': 'newCaps',
'options': {
'testCapabilitiesOne': 'capabilityOne'
}
});

client.updateCapabilities({
'testName': 'updatedCaps',
'options': {
'testCapabilitiesTwo': 'capabilityTwo'
}
});

const session = await client.launchBrowser();
assert.deepStrictEqual(session.desiredCapabilities, {
browserName: 'firefox',
testName: 'updatedCaps',
options: {
testCapabilitiesOne: 'capabilityOne',
testCapabilitiesTwo: 'capabilityTwo'
}
});
CliRunner.createDefaultConfig = createDefaultConfig;
CliRunner.prototype.loadConfig = loadConfig;
});
});

0 comments on commit adf2944

Please sign in to comment.