Skip to content

Commit ad11a61

Browse files
[js] Add Enable Mobile feature for Firefox
Still need to expand this to chromium based browsers
1 parent e5968b6 commit ad11a61

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

javascript/node/selenium-webdriver/firefox.js

+27-9
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ async function buildProfile(template, extensions) {
222222
dir = await io.tmpDir()
223223
if (template) {
224224
await io.copyDir(
225-
/** @type {string} */ (template),
225+
/** @type {string} */(template),
226226
dir,
227227
/(parent\.lock|lock|\.parentlock)/
228228
)
@@ -393,6 +393,24 @@ class Options extends Capabilities {
393393
}
394394
throw TypeError('binary must be a string path or Channel object')
395395
}
396+
397+
/**
398+
* Enables Mobile start up features
399+
*
400+
* @param {string} androidPackage The package to use
401+
* @return {!Options} A self reference
402+
*/
403+
enableMobile(androidPackage = "org.mozilla.firefox", androidActivity = null, deviceSerial = null) {
404+
this.firefoxOptions_().androidPackage = androidPackage
405+
406+
if (androidActivity) {
407+
this.firefoxOptions_().androidActivity = androidActivity
408+
}
409+
if (deviceSerial) {
410+
this.firefoxOptions_().deviceSerial = deviceSerial
411+
}
412+
return this
413+
}
396414
}
397415

398416
/**
@@ -432,11 +450,11 @@ function findGeckoDriver() {
432450
if (!exe) {
433451
throw Error(
434452
'The ' +
435-
GECKO_DRIVER_EXE +
436-
' executable could not be found on the current ' +
437-
'PATH. Please download the latest version from ' +
438-
'https://github.com/mozilla/geckodriver/releases/ ' +
439-
'and ensure it can be found on your PATH.'
453+
GECKO_DRIVER_EXE +
454+
' executable could not be found on the current ' +
455+
'PATH. Please download the latest version from ' +
456+
'https://github.com/mozilla/geckodriver/releases/ ' +
457+
'and ensure it can be found on your PATH.'
440458
)
441459
}
442460
return exe
@@ -457,8 +475,8 @@ function findInProgramFiles(file) {
457475
return exists
458476
? files[0]
459477
: io.exists(files[1]).then(function (exists) {
460-
return exists ? files[1] : null
461-
})
478+
return exists ? files[1] : null
479+
})
462480
})
463481
}
464482

@@ -592,7 +610,7 @@ class Driver extends webdriver.WebDriver {
592610
* implementation.
593611
* @override
594612
*/
595-
setFileDetector() {}
613+
setFileDetector() { }
596614

597615
/**
598616
* Get the context that is currently in effect.

javascript/node/selenium-webdriver/test/firefox_test.js

+8
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ suite(
9595
})
9696
})
9797

98+
describe('set mobile options', function () {
99+
it('allows setting android activity', function () {
100+
let options = new firefox.Options().enableMobile()
101+
let firefoxOptions = options.firefoxOptions_()
102+
assert.deepStrictEqual({ "androidPackage": "org.mozilla.firefox" }, firefoxOptions)
103+
})
104+
})
105+
98106
describe('setPreference', function () {
99107
it('throws if key is not a string', function () {
100108
let options = new firefox.Options()

0 commit comments

Comments
 (0)