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
Improve Appium support in Nightwatch #3519
Changes from 21 commits
0531906
e6846e9
752812a
124b46e
f9d4c14
39eca9f
f058e1f
9d56c82
a8d2c11
8916448
709fd41
7b40016
c76e481
e6c85aa
e000786
1167538
d7a996e
bf62d81
48bb1b9
273af20
27ba564
54587b1
0706064
79bebbb
019b395
e7fac99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const SeleniumServer = require('./selenium'); | ||
const AppiumServiceBuilder = require('./service-builders/appium'); | ||
const AppiumMixin = require('./appiumMixin'); | ||
|
||
|
||
class AppiumServer extends SeleniumServer { | ||
static startServer(settings) { | ||
const Options = require('./options.js'); | ||
const opts = new Options({settings}); | ||
opts.updateWebdriverPath(); | ||
|
||
const appiumService = new AppiumServiceBuilder(settings); | ||
|
||
const outputFile = settings.webdriver.log_file_name || ''; | ||
appiumService.setOutputFile(outputFile); | ||
|
||
return appiumService; | ||
} | ||
|
||
get defaultBrowser() { | ||
return null; | ||
} | ||
|
||
get ServiceBuilder() { | ||
return AppiumServiceBuilder; | ||
} | ||
|
||
get defaultServerUrl() { | ||
return 'http://127.0.0.1:4723'; | ||
} | ||
|
||
get defaultPort() { | ||
return 4723; | ||
} | ||
|
||
get defaultPathPrefix() { | ||
return '/wd/hub'; | ||
} | ||
|
||
createSessionOptions(argv) { | ||
this.extractAppiumOptions(); | ||
|
||
// if `appium:chromedriverExecutable` is present and left blank, | ||
// assign the path of binary from `chromedriver` NPM package to it. | ||
if (this.desiredCapabilities['appium:chromedriverExecutable'] === '') { | ||
const chromedriver = this.seleniumCapabilities.getChromedriverPath(); | ||
if (chromedriver) { | ||
this.desiredCapabilities['appium:chromedriverExecutable'] = chromedriver; | ||
} | ||
} | ||
|
||
return super.createSessionOptions(argv) || this.desiredCapabilities; | ||
} | ||
|
||
createDriver({options}) { | ||
return this.createAppiumDriver({options}); | ||
} | ||
}; | ||
|
||
Object.assign(AppiumServer.prototype, AppiumMixin); | ||
|
||
module.exports = AppiumServer; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const {WebDriver} = require('selenium-webdriver'); | ||
const {Executor} = require('selenium-webdriver/http'); | ||
const http = require('selenium-webdriver/http'); | ||
const {isObject} = require('../../utils'); | ||
|
||
const AppiumMixin = { | ||
createAppiumDriver({options}) { | ||
const httpClient = new http.HttpClient(this.getServerUrl()); | ||
|
||
return WebDriver.createSession(new Executor(httpClient), options); | ||
}, | ||
|
||
extractAppiumOptions() { | ||
// break 'appium:options' to individual configs | ||
if (isObject(this.desiredCapabilities['appium:options'])) { | ||
const appiumOptions = this.desiredCapabilities['appium:options']; | ||
for (let key of Object.keys(appiumOptions)) { | ||
const value = appiumOptions[key]; | ||
|
||
if (!key.startsWith('appium:')) { | ||
key = `appium:${key}`; | ||
} | ||
this.desiredCapabilities[key] = value; | ||
} | ||
|
||
delete this.desiredCapabilities['appium:options']; | ||
} | ||
} | ||
}; | ||
|
||
module.exports = AppiumMixin; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const BrowserStack = require('./browserstack.js'); | ||
const AppiumMixin = require('../appiumMixin.js'); | ||
|
||
class AppAutomate extends BrowserStack { | ||
get ApiUrl() { | ||
return `https://api.browserstack.com/${this.productNamespace}`; | ||
} | ||
|
||
get productNamespace() { | ||
return 'app-automate'; | ||
} | ||
|
||
createSessionOptions() { | ||
this.extractAppiumOptions(); | ||
|
||
return this.desiredCapabilities; | ||
} | ||
|
||
createDriver({options}) { | ||
return this.createAppiumDriver({options}); | ||
} | ||
} | ||
|
||
Object.assign(AppAutomate.prototype, AppiumMixin); | ||
|
||
module.exports = AppAutomate; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const BrowserStack = require('./browserstack.js'); | ||
const AppiumMixin = require('../appiumMixin.js'); | ||
const {Capabilities} = require('selenium-webdriver'); | ||
|
||
class Automate extends BrowserStack { | ||
get ApiUrl() { | ||
return `https://api.browserstack.com/${this.productNamespace}`; | ||
} | ||
|
||
get productNamespace() { | ||
return 'automate'; | ||
} | ||
|
||
createDriver({options = this.desiredCapabilities}) { | ||
if (options instanceof Capabilities) { | ||
return super.createDriver({options}); | ||
} | ||
|
||
return this.createAppiumDriver({options}); | ||
} | ||
} | ||
|
||
Object.assign(Automate.prototype, AppiumMixin); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can't we use normal inheritance here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could but then But then, as I think now, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or both browserstack and appium could extend a base class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please check 0706064. |
||
|
||
module.exports = Automate; |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should use a factory here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean
factory
as variable name or use aTransportFactory
class method to decide whether appium is being used or not?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use a factory to create the server
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check 54587b1 if it is fine.