From de6c02fdcbda060bf8f7099d76e7a08eacb00036 Mon Sep 17 00:00:00 2001 From: SvetoslavTsenov Date: Mon, 11 Nov 2019 14:14:49 +0200 Subject: [PATCH] fix: resolve device type by device name --- lib/appium-driver.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/appium-driver.ts b/lib/appium-driver.ts index 81c4e78..dabe2b2 100644 --- a/lib/appium-driver.ts +++ b/lib/appium-driver.ts @@ -318,10 +318,16 @@ export class AppiumDriver { && sessionInfoDetails.platformName.toLowerCase() === "ios" && sessionInfoDetails.platformVersion.startsWith("13")) { try { - const devicesInfos = IOSController.devicesDisplaysInfos(); - const matches = devicesInfos.filter(d => sessionInfoDetails.deviceName.includes(d.deviceType)); - if (matches && matches.length > 0) { - const deviceType = matches[matches.length - 1]; + const devicesInfos = IOSController.devicesDisplaysInfos() + .filter(d => sessionInfoDetails.deviceName.includes(d.deviceType)); + + if (devicesInfos.length > 0) { + // sort devices by best match - in case we have iPhone XR 13 -> it will match device type 'iPhone X' and 'iPhone XR' -> after sort we will pick first longest match + devicesInfos + .sort((a, b) => { + return sessionInfoDetails.deviceName.replace(a.deviceType, "").length - sessionInfoDetails.deviceName.replace(b.deviceType, "").length + }); + const deviceType = devicesInfos[0]; args.device.viewportRect.y += deviceType.actionBarHeight; args.device.viewportRect.height -= deviceType.actionBarHeight; }