Skip to content

Commit

Permalink
Fix native testing with test_workers enabled. (#3559)
Browse files Browse the repository at this point in the history
  • Loading branch information
garg3133 authored Jan 9, 2023
1 parent 0e02f5d commit 06d3598
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
7 changes: 4 additions & 3 deletions lib/core/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const Transport = require('../transport');
const Element = require('../element');
const ApiLoader = require('../api');
const ElementGlobal = require('../api/_loaders/element-global.js');
const {isAndroid, isIos} = require('../utils/mobile');

const {LocateStrategy, Locator} = Element;
const {Logger, isUndefined, isDefined, isObject, isFunction} = Utils;
Expand Down Expand Up @@ -37,7 +38,7 @@ class NightwatchAPI {
}

if (this.desiredCapabilities instanceof Capabilities) {
return this.desiredCapabilities.getplatformName();
return this.desiredCapabilities.getPlatform();
}

return this.desiredCapabilities.platformName;
Expand Down Expand Up @@ -79,11 +80,11 @@ class NightwatchAPI {
}

isIOS() {
return this.__isPlatformName('iOS');
return isIos(this.desiredCapabilities);
}

isAndroid() {
return this.__isPlatformName('Android');
return isAndroid(this.desiredCapabilities);
}

isMobile() {
Expand Down
14 changes: 10 additions & 4 deletions lib/utils/mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ function requireMobileHelper() {
* @param {Object} desiredCapabilities
* @returns {Boolean}
*/
function isAndroid(desiredCapabilities){
function isAndroid(desiredCapabilities = {}){
const {platformName} = desiredCapabilities;

if (platformName && platformName.toLowerCase() === 'android') {
return true;
}

const options = desiredCapabilities['goog:chromeOptions'] || desiredCapabilities['moz:firefoxOptions'];

if (options && options.androidPackage) {
Expand All @@ -44,10 +50,10 @@ function isAndroid(desiredCapabilities){
* @param {Object} desiredCapabilities
* @returns {Boolean}
*/
function isIos(desiredCapabilities) {
const {browserName = '', platformName = ''} = desiredCapabilities;
function isIos(desiredCapabilities = {}) {
const {platformName} = desiredCapabilities;

if (browserName.toLowerCase() === 'safari' && platformName.toLowerCase() === 'ios') {
if (platformName && platformName.toLowerCase() === 'ios') {
return true;
}

Expand Down
8 changes: 4 additions & 4 deletions test/src/index/transport/testMobileOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ describe('Test mobile options in Nightwatch/Appium client', function () {
desiredCapabilities: {
browserName: 'Chrome',
javascriptEnabled: true,
platformName: 'Android',
platformVersion: '13.0',
deviceName: 'Google Pixel'
'goog:chromeOptions': {
androidPackage: 'com.android.chrome'
}
}
});

Expand Down Expand Up @@ -94,7 +94,7 @@ describe('Test mobile options in Nightwatch/Appium client', function () {
use_appium: true
},
desiredCapabilities: {
browserName: '',
browserName: null,
platformName: 'Android'
}
});
Expand Down

0 comments on commit 06d3598

Please sign in to comment.