Skip to content

Commit

Permalink
Do not prefer unprefixed chromeOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
imurchie committed Dec 27, 2017
1 parent 8770290 commit 8bb5a13
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
20 changes: 9 additions & 11 deletions lib/commands/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,18 @@ async function setupNewChromedriver (opts, curDeviceId, adb) {
};
let chromedriver = new Chromedriver(chromeArgs);

// prefer `chromeOptions` capability
if (!opts.chromeOptions) {
// try out any prefixed chromeOptions,
// and strip the prefix
opts.chromeOptions = {};
for (let opt of _.keys(opts)) {
if (opt.includes('chromeOptions')) {
logger.warn(`Merging '${opt}' into 'chromeOptions'. This may cause unexpected behavior`);
_.merge(opts.chromeOptions, opts[opt]);
}
// make sure there are chromeOptions
opts.chromeOptions = opts.chromeOptions || {};
// try out any prefixed chromeOptions,
// and strip the prefix
for (let opt of _.keys(opts)) {
if (opt.includes(':chromeOptions')) {
logger.warn(`Merging '${opt}' into 'chromeOptions'. This may cause unexpected behavior`);
_.merge(opts.chromeOptions, opts[opt]);
}
}

let appPackage = (opts.chromeOptions && opts.chromeOptions.androidPackage) || opts.appPackage;
let appPackage = opts.chromeOptions.androidPackage || opts.appPackage;
let caps = {
chromeOptions: {
androidPackage: appPackage,
Expand Down
21 changes: 7 additions & 14 deletions test/unit/commands/context-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,31 +237,22 @@ describe('Context', function () {
chromedriver.start.getCall(0).args[0].chromeOptions.androidPackage
.should.be.equal('apkg');
});
it('should prefer unprefixed chromeOptions', async function () {
it('should use prefixed chromeOptions', async function () {
let chromedriver = await setupNewChromedriver({
chromeOptions: {
androidPackage: 'apkg',
},
'goog:chromeOptions': {
androidPackage: 'bpkg',
androidPackage: 'apkg',
},
});
chromedriver.start.getCall(0).args[0].chromeOptions.androidPackage
.should.be.equal('apkg');
});
it('should use prefixed chromeOptions if necessary', async function () {
it('should merge chromeOptions', async function () {
let chromedriver = await setupNewChromedriver({
'goog:chromeOptions': {
chromeOptions: {
androidPackage: 'apkg',
},
});
chromedriver.start.getCall(0).args[0].chromeOptions.androidPackage
.should.be.equal('apkg');
});
it('should merge prefixed chromeOptions if necessary', async function () {
let chromedriver = await setupNewChromedriver({
'goog:chromeOptions': {
androidPackage: 'apkg',
androidWaitPackage: 'bpkg',
},
'appium:chromeOptions': {
androidActivity: 'aact',
Expand All @@ -271,6 +262,8 @@ describe('Context', function () {
.should.be.equal('apkg');
chromedriver.start.getCall(0).args[0].chromeOptions.androidActivity
.should.be.equal('aact');
chromedriver.start.getCall(0).args[0].chromeOptions.androidWaitPackage
.should.be.equal('bpkg');
});
it('should be able to set androidActivity chrome option', async function () {
let chromedriver = await setupNewChromedriver({chromeAndroidActivity: 'act'});
Expand Down

0 comments on commit 8bb5a13

Please sign in to comment.