Skip to content
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

Merged
merged 26 commits into from Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0531906
Automatically start appium server in Nightwatch.
garg3133 Dec 13, 2022
e6846e9
Create separate startServer method in AppiumServer.
garg3133 Dec 15, 2022
752812a
Convert relative paths to absolute paths for Appium.
garg3133 Dec 21, 2022
124b46e
Remove appium_version, for now.
garg3133 Dec 21, 2022
f9d4c14
Use chromedriver npm package if path not explicitely passed.
garg3133 Dec 22, 2022
39eca9f
Add tests for appium session and service builder.
garg3133 Dec 23, 2022
f058e1f
Add more tests for changes.
garg3133 Dec 25, 2022
9d56c82
Fix testAppiumOptions tests.
garg3133 Dec 25, 2022
a8d2c11
Add backward compatibility for browserName=null.
garg3133 Dec 26, 2022
8916448
Skip Appium's createSessionOptions for BrowserStack.
garg3133 Dec 26, 2022
709fd41
Fix tests.
garg3133 Dec 26, 2022
7b40016
Fix client.click() test.
garg3133 Dec 26, 2022
c76e481
isAppium -> use_appium
garg3133 Dec 26, 2022
e6c85aa
Remove the logic for converting relative paths to absolute for Appium.
garg3133 Dec 29, 2022
e000786
Resolve BrowserStack related issues.
garg3133 Dec 29, 2022
1167538
Create separate classes for Automate and AppAutomate.
garg3133 Dec 30, 2022
d7a996e
Modify BrowserStack's folder structure.
garg3133 Jan 3, 2023
bf62d81
Fix appium server tests.
garg3133 Jan 3, 2023
48bb1b9
Fix import paths.
garg3133 Jan 3, 2023
273af20
Add browserstack transport and createSession tests.
garg3133 Jan 3, 2023
27ba564
Increase appium server startup timeout to 15sec.
garg3133 Jan 4, 2023
54587b1
Create a factory method to create service.
garg3133 Jan 4, 2023
0706064
AppiumMixin -> AppiumBaseServer.
garg3133 Jan 4, 2023
79bebbb
Pass udid using --deviceId flag.
garg3133 Jan 4, 2023
019b395
Fix failing tests.
garg3133 Jan 4, 2023
e7fac99
Remove unused function from testAppiumServer.
garg3133 Jan 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions lib/transport/factory.js
Expand Up @@ -48,20 +48,20 @@ module.exports = class TransportFactory {

let {browserName} = settings.desiredCapabilities;

// Better support for Appium, if the browserName has explicitly been set to null we can skip all further checks
if (settings.selenium && settings.selenium.use_appium && !browserName) {
// Better support for app-testing, if the browserName is not present we can skip all further checks
const usingAppium = TransportFactory.usingSeleniumServer(settings) && settings.selenium.use_appium;
const usingBrowserStack = TransportFactory.usingBrowserstack(settings);
if ((usingAppium || usingBrowserStack) && !browserName) {
return browserName;
}

// for backward compatibility
if (browserName === null) {
// TODO:
// Deprecation warning: Setting browserName to null for running Appium tests has
// now been deprecated and will be removed from future versions. Set `use_appium`
// property to true in `selenium` config to run Appium tests.
//
// put a warning here that if trying to connect to an Appium server,
// just setting browserName=null will not work in the future.
// eslint-disable-next-line no-console
console.warn('DEPRECATED: Setting browserName=null for running Appium tests has been deprecated ' +
'and will not be supported in future versions. Set `use_appium` property in `selenium` config to true ' +
'in your Nightwatch configuration file to run Appium tests.');

settings.selenium.use_appium = true;

return browserName;
Expand Down
30 changes: 13 additions & 17 deletions lib/transport/selenium-webdriver/appium.js
Expand Up @@ -43,45 +43,41 @@ module.exports = class AppiumServer extends SeleniumServer {
}

createSessionOptions(argv) {
// TODO: Re-think the below temp solution
if (TransportFactory.usingBrowserstack(this.settings)) {
return super.createSessionOptions(argv);
}

const options = this.desiredCapabilities;

// break 'appium:options' to individual configs
if (isObject(options['appium:options'])) {
const appiumOptions = options['appium:options'];
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}`;
}
options[key] = value;
this.desiredCapabilities[key] = value;
}

delete options['appium:options'];
delete this.desiredCapabilities['appium:options'];
}

// if `appium:chromedriverExecutable` is present and left blank,
// assign the path of binary from `chromedriver` NPM package to it.
if (options['appium:chromedriverExecutable'] === '') {
if (this.desiredCapabilities['appium:chromedriverExecutable'] === '') {
const chromedriver = this.seleniumCapabilities.getChromedriverPath();
if (chromedriver) {
options['appium:chromedriverExecutable'] = chromedriver;
this.desiredCapabilities['appium:chromedriverExecutable'] = chromedriver;
}
}

return options;
return super.createSessionOptions(argv) || this.desiredCapabilities;
}

createDriver({options = this.desiredCapabilities} = {}) {
const httpClient = new http.HttpClient(this.getServerUrl());
// If creating a session with BrowserStack Automate, use Selenium's session builder.
if (TransportFactory.usingBrowserstack(this.settings) && this.productNamespace === 'automate') {
return super.createDriver({options});
}
garg3133 marked this conversation as resolved.
Show resolved Hide resolved

const session = WebDriver.createSession(new Executor(httpClient), options);
const httpClient = new http.HttpClient(this.getServerUrl());

return session;
return WebDriver.createSession(new Executor(httpClient), options);
}
};
6 changes: 3 additions & 3 deletions lib/transport/selenium-webdriver/browserstack.js
Expand Up @@ -5,7 +5,7 @@ const defaultsDeep = require('lodash.defaultsdeep');

class Browserstack extends BaseDriver {
get ApiUrl() {
return `https://api.browserstack.com/${this.isMobile ? 'app-automate' : 'automate'}`;
return `https://api.browserstack.com/${this.productNamespace}`;
}

bStackOptions() {
Expand All @@ -31,7 +31,7 @@ class Browserstack extends BaseDriver {
constructor(nightwatchInstance, browserName) {
super(nightwatchInstance, browserName);

this.isMobile = this.api.isMobile();
this.productNamespace = browserName ? 'automate' : 'app-automate';
garg3133 marked this conversation as resolved.
Show resolved Hide resolved
this.useLocal = false;

this.nightwatchInstance.on('nightwatch:session.create', (data) => {
Expand Down Expand Up @@ -146,7 +146,7 @@ class Browserstack extends BaseDriver {
await this.sendReasonToBrowserstack(!!failures, reason);
// eslint-disable-next-line no-console
console.log('\n ' + 'See more info, video, & screenshots on Browserstack:\n' +
' ' + Logger.colors.light_cyan(`https://${this.isMobile ? 'app-automate' : 'automate'}.browserstack.com/builds/${this.buildId}/sessions/${this.sessionId}`));
' ' + Logger.colors.light_cyan(`https://${this.productNamespace}.browserstack.com/builds/${this.buildId}/sessions/${this.sessionId}`));

this.sessionId = null;

Expand Down