From c6735df1a77e090b9a73e724e7a48060d8701663 Mon Sep 17 00:00:00 2001 From: saikrishna321 Date: Thu, 1 Apr 2021 09:47:53 +0530 Subject: [PATCH] fix simulator run parallel with android --- package-lock.json | 2 +- package.json | 2 +- src/CapabilityManager.js | 13 +++++++++++++ src/Devices.js | 3 ++- src/plugin.js | 12 ++++-------- 5 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 src/CapabilityManager.js diff --git a/package-lock.json b/package-lock.json index 682e825f5..de89bdeca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "appium-device-plugin", - "version": "1.0.0-beta.2", + "version": "1.0.0-beta.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 0d3f98c0b..806be87a5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "appium-device-plugin", - "version": "1.0.0-beta.2", + "version": "1.0.0-beta.3", "description": "An appium 2.0 plugin that manages and create driver session on available devices", "main": "./lib/index.js", "scripts": { diff --git a/src/CapabilityManager.js b/src/CapabilityManager.js new file mode 100644 index 000000000..b204ae9ee --- /dev/null +++ b/src/CapabilityManager.js @@ -0,0 +1,13 @@ +import getPort from 'get-port'; + +export async function androidCapabilities(caps, freeDevice) { + caps.firstMatch[0]['appium:udid'] = freeDevice.udid; + caps.firstMatch[0]['appium:deviceName'] = freeDevice.udid; + caps.firstMatch[0]['appium:systemPort'] = await getPort(); +} + +export async function iOSCapabilities(caps, freeDevice) { + caps.firstMatch[0]['appium:udid'] = freeDevice.udid; + caps.firstMatch[0]['appium:deviceName'] = freeDevice.udid; + caps.firstMatch[0]['appium:wdaLocalPort'] = await getPort(); +} diff --git a/src/Devices.js b/src/Devices.js index 30761c089..9a0ab6131 100644 --- a/src/Devices.js +++ b/src/Devices.js @@ -48,7 +48,8 @@ export default class Devices { getFreeDevice(platform) { log.info(`Finding Free Device for Platform ${platform}`); return actualDevices.find( - (device) => device.busy === false && device.platform === platform + (device) => + device.busy === false && device.platform.toLowerCase() === platform ); } diff --git a/src/plugin.js b/src/plugin.js index 0a5117f48..b5e5912ca 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -1,6 +1,6 @@ import BasePlugin from '@appium/base-plugin'; import AndroidDeviceManager from './AndroidDeviceManager'; -import getPort from 'get-port'; +import { androidCapabilities, iOSCapabilities } from './CapabilityManager'; import log from './logger'; import Devices from './Devices'; import SimulatorManager from './SimulatorManager'; @@ -32,15 +32,11 @@ export default class DevicePlugin extends BasePlugin { await fetchDevices(); freeDevice = devices.getFreeDevice(caps.firstMatch[0]['platformName']); if (freeDevice && caps.firstMatch[0]['platformName'] === 'android') { - caps.firstMatch[0]['appium:udid'] = freeDevice.udid; - caps.firstMatch[0]['appium:deviceName'] = freeDevice.udid; - caps.firstMatch[0]['appium:systemPort'] = await getPort(); + await androidCapabilities(caps, freeDevice); devices.blockDevice(freeDevice); log.info(`Device UDID ${freeDevice.udid} is blocked for execution.`); - } else if (freeDevice && caps.firstMatch[0]['platformName'] === 'iOS') { - caps.firstMatch[0]['appium:udid'] = freeDevice.udid; - caps.firstMatch[0]['appium:deviceName'] = freeDevice.udid; - caps.firstMatch[0]['appium:wdaLocalPort'] = await getPort(); + } else if (freeDevice && caps.firstMatch[0]['platformName'] === 'ios') { + await iOSCapabilities(caps, freeDevice); devices.blockDevice(freeDevice); log.info(`Device UDID ${freeDevice.udid} is blocked for execution.`); } else {