From 06d35988ac6fba96a10c7af28df0a1a9a74589f3 Mon Sep 17 00:00:00 2001 From: Priyansh Garg <39924567+garg3133@users.noreply.github.com> Date: Mon, 9 Jan 2023 20:10:22 +0530 Subject: [PATCH] Fix native testing with test_workers enabled. (#3559) --- lib/core/client.js | 7 ++++--- lib/utils/mobile.js | 14 ++++++++++---- test/src/index/transport/testMobileOptions.js | 8 ++++---- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/core/client.js b/lib/core/client.js index 8e336272cf..86efaa2c57 100644 --- a/lib/core/client.js +++ b/lib/core/client.js @@ -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; @@ -37,7 +38,7 @@ class NightwatchAPI { } if (this.desiredCapabilities instanceof Capabilities) { - return this.desiredCapabilities.getplatformName(); + return this.desiredCapabilities.getPlatform(); } return this.desiredCapabilities.platformName; @@ -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() { diff --git a/lib/utils/mobile.js b/lib/utils/mobile.js index e1cbfba6fd..9a8bca043e 100644 --- a/lib/utils/mobile.js +++ b/lib/utils/mobile.js @@ -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) { @@ -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; } diff --git a/test/src/index/transport/testMobileOptions.js b/test/src/index/transport/testMobileOptions.js index f0d94783bd..5a88af3f9d 100644 --- a/test/src/index/transport/testMobileOptions.js +++ b/test/src/index/transport/testMobileOptions.js @@ -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' + } } }); @@ -94,7 +94,7 @@ describe('Test mobile options in Nightwatch/Appium client', function () { use_appium: true }, desiredCapabilities: { - browserName: '', + browserName: null, platformName: 'Android' } });