Skip to content

Commit e7d7345

Browse files
fix: resolve device type by device name (#277)
1 parent dff2e07 commit e7d7345

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Diff for: lib/appium-driver.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,16 @@ export class AppiumDriver {
318318
&& sessionInfoDetails.platformName.toLowerCase() === "ios"
319319
&& sessionInfoDetails.platformVersion.startsWith("13")) {
320320
try {
321-
const devicesInfos = IOSController.devicesDisplaysInfos();
322-
const matches = devicesInfos.filter(d => sessionInfoDetails.deviceName.includes(d.deviceType));
323-
if (matches && matches.length > 0) {
324-
const deviceType = matches[matches.length - 1];
321+
const devicesInfos = IOSController.devicesDisplaysInfos()
322+
.filter(d => sessionInfoDetails.deviceName.includes(d.deviceType));
323+
324+
if (devicesInfos.length > 0) {
325+
// 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
326+
devicesInfos
327+
.sort((a, b) => {
328+
return sessionInfoDetails.deviceName.replace(a.deviceType, "").length - sessionInfoDetails.deviceName.replace(b.deviceType, "").length
329+
});
330+
const deviceType = devicesInfos[0];
325331
args.device.viewportRect.y += deviceType.actionBarHeight;
326332
args.device.viewportRect.height -= deviceType.actionBarHeight;
327333
}

0 commit comments

Comments
 (0)