From d612a8fe115708bee4055dff34b2ffe882e88298 Mon Sep 17 00:00:00 2001 From: SvetoslavTsenov Date: Thu, 3 Oct 2019 00:34:12 +0300 Subject: [PATCH 1/4] fix(ios): ios13 statusbar height --- lib/appium-driver.d.ts | 1 - lib/appium-driver.ts | 34 ++++++++++++++++++++++++---------- lib/device-manager.d.ts | 2 +- lib/device-manager.ts | 4 ++-- lib/parser.d.ts | 2 +- package.json | 2 +- 6 files changed, 29 insertions(+), 16 deletions(-) diff --git a/lib/appium-driver.d.ts b/lib/appium-driver.d.ts index 5746907..d38811e 100644 --- a/lib/appium-driver.d.ts +++ b/lib/appium-driver.d.ts @@ -271,7 +271,6 @@ export declare class AppiumDriver { getScreenViewPort(): IRectangle; /** * Android ONLY! Input key event via ADB. - * Must be combined with '--relaxed-security' appium flag. When not running in sauceLabs '--ignoreDeviceController' should be added too. * @param keyEvent The event number */ adbKeyEvent(keyEvent: number | AndroidKeyEvent): Promise; diff --git a/lib/appium-driver.ts b/lib/appium-driver.ts index 513e075..ca039d2 100644 --- a/lib/appium-driver.ts +++ b/lib/appium-driver.ts @@ -11,7 +11,8 @@ import { DeviceController, IDevice, DeviceType, - AndroidController + AndroidController, + IOSController } from "mobile-devices-controller"; import { addExt, @@ -47,6 +48,7 @@ import { DeviceOrientation } from "./enums/device-orientation"; import { NsCapabilities } from "./ns-capabilities"; import { AutomationName } from "./automation-name"; import { AndroidKeyEvent } from "mobile-devices-controller"; +import { setInterval } from "timers"; export class AppiumDriver { private _defaultWaitTime: number = 5000; @@ -215,10 +217,11 @@ export class AppiumDriver { let hasStarted = false; let retries = 10; + let sessionInfoDetails; + while (retries > 0 && !hasStarted) { try { let sessionInfo; - let sessionInfoDetails; try { if (args.sessionId || args.attachToDebug) { const sessionInfos = JSON.parse(((await getSessions(args.port)) || "{}") + ''); @@ -311,7 +314,19 @@ export class AppiumDriver { await driver.updateSettings(appiumCapsFromConfig.settings); } - return new AppiumDriver(driver, wd, webio, args.driverConfig, args); + if (+sessionInfoDetails.statBarHeight === 0 + && sessionInfoDetails.platformName.toLowerCase() === "ios" + && sessionInfoDetails.platformVersion.startsWith("13")) { + try { + const devicesInfos = IOSController.devicesDisplaysInfos(); + const matches = devicesInfos.filter(d => sessionInfoDetails.deviceName.includes(d.deviceType)); + const deviceType = matches[matches.length - 1]; + args.device.viewportRect.y += deviceType.statBarHeight * deviceType.density; + } catch (error) { } + } + + const appiumDriver = new AppiumDriver(driver, wd, webio, args.driverConfig, args); + return appiumDriver; } public async updateSettings(settings: any) { @@ -1011,23 +1026,22 @@ export class AppiumDriver { public getScreenViewPort(): IRectangle { const rect = this.getScreenActualViewPort(); if (rect + && this.isIOS && Object.getOwnPropertyNames(rect).length > 0 - && this._args.appiumCaps.device.deviceScreenDensity) { + && this._args.device.deviceScreenDensity) { return { - x: rect.x / this._args.appiumCaps.device.deviceScreenDensity, - y: rect.y / this._args.appiumCaps.device.deviceScreenDensity, - width: rect.width / this._args.appiumCaps.device.deviceScreenDensity, - height: rect.height / this._args.appiumCaps.device.deviceScreenDensity, + x: rect.x / this._args.device.deviceScreenDensity, + y: rect.y / this._args.device.deviceScreenDensity, + width: rect.width / this._args.device.deviceScreenDensity, + height: rect.height / this._args.device.deviceScreenDensity, } } else { - logError("Device's density is undefined!"); return rect; } } /** * Android ONLY! Input key event via ADB. - * Must be combined with '--relaxed-security' appium flag. When not running in sauceLabs '--ignoreDeviceController' should be added too. * @param keyEvent The event number */ public async adbKeyEvent(keyEvent: number | AndroidKeyEvent) { diff --git a/lib/device-manager.d.ts b/lib/device-manager.d.ts index e535392..f0bdbe6 100644 --- a/lib/device-manager.d.ts +++ b/lib/device-manager.d.ts @@ -13,7 +13,7 @@ export declare class DeviceManager implements IDeviceManager { static getInstalledApps(device: IDevice): Promise; static getDefaultDevice(args: INsCapabilities, deviceName?: string, token?: string, type?: DeviceType, platformVersion?: number): IDevice; private static convertViewportRectToIRectangle; - static applyAppiumSessionInfoDetails(args: INsCapabilities, sessionInfoDetails: any): IDevice; + static applyAppiumSessionInfoDetails(args: INsCapabilities, sessionInfoDetails: any): any; static setDontKeepActivities(args: INsCapabilities, driver: any, value: any): Promise; static executeShellCommand(driver: any, commandArgs: { command: string; diff --git a/lib/device-manager.ts b/lib/device-manager.ts index dc51caa..50e7d0e 100644 --- a/lib/device-manager.ts +++ b/lib/device-manager.ts @@ -261,7 +261,7 @@ export class DeviceManager implements IDeviceManager { if (args.device.name.includes(k)) { args.device.config = { density: args.device.config['density'] || v.density, - offsetPixels: v.actionBarHeight + offsetPixels: v.actionBarHeight * (args.device.config['density'] || v.density) }; } }); @@ -289,7 +289,7 @@ export class DeviceManager implements IDeviceManager { args.device.config['offsetPixels'] = AndroidController.calculateScreenOffset(args.device.config.density); } - if (!density) { + if (!density && !args.isIOS) { await DeviceManager.getDensity(args, driver); density = args.device.config.density args.device.config['offsetPixels'] = AndroidController.calculateScreenOffset(args.device.config.density); diff --git a/lib/parser.d.ts b/lib/parser.d.ts index 386ae5d..40edb2e 100644 --- a/lib/parser.d.ts +++ b/lib/parser.d.ts @@ -1,2 +1,2 @@ import { LogImageType } from "./enums/log-image-type"; -export declare const projectDir: string, projectBinary: string, pluginRoot: string, pluginBinary: string, port: number, verbose: boolean, appiumCapsLocation: string, testFolder: string, runType: string, isSauceLab: boolean, appPath: string, storage: string, testReports: string, devMode: boolean, ignoreDeviceController: boolean, wdaLocalPort: number, path: string, relaxedSecurity: boolean, cleanApp: boolean, attachToDebug: boolean, sessionId: string, startSession: boolean, capabilitiesName: string, imagesPath: string, startDeviceOptions: string, deviceTypeOrPlatform: string, device: import("mobile-devices-controller/lib/device").IDevice, driverConfig: any, logImageTypes: LogImageType[], appiumCaps: any; +export declare const projectDir: string, projectBinary: string, pluginRoot: string, pluginBinary: string, port: number, verbose: boolean, appiumCapsLocation: string, testFolder: string, runType: string, isSauceLab: boolean, appPath: string, storage: string, testReports: string, devMode: boolean, ignoreDeviceController: boolean, wdaLocalPort: number, path: string, relaxedSecurity: boolean, cleanApp: boolean, attachToDebug: boolean, sessionId: string, startSession: boolean, capabilitiesName: string, imagesPath: string, startDeviceOptions: string, deviceTypeOrPlatform: string, device: any, driverConfig: any, logImageTypes: LogImageType[], appiumCaps: any; diff --git a/package.json b/package.json index 901be07..0a5f2b9 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "frame-comparer": "^2.0.1", "glob": "^7.1.0", "inquirer": "^6.2.0", - "mobile-devices-controller": "^5.0.0", + "mobile-devices-controller": "^5.1.0", "wd": "~1.11.3", "webdriverio": "~4.14.0", "yargs": "~12.0.5" From f15ce3f56db8f61fbcd0bfb75614fc6e8023862e Mon Sep 17 00:00:00 2001 From: SvetoslavTsenov Date: Thu, 3 Oct 2019 11:51:49 +0300 Subject: [PATCH 2/4] chore: revert comment of method --- lib/appium-driver.d.ts | 1 + lib/appium-driver.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/appium-driver.d.ts b/lib/appium-driver.d.ts index d38811e..5746907 100644 --- a/lib/appium-driver.d.ts +++ b/lib/appium-driver.d.ts @@ -271,6 +271,7 @@ export declare class AppiumDriver { getScreenViewPort(): IRectangle; /** * Android ONLY! Input key event via ADB. + * Must be combined with '--relaxed-security' appium flag. When not running in sauceLabs '--ignoreDeviceController' should be added too. * @param keyEvent The event number */ adbKeyEvent(keyEvent: number | AndroidKeyEvent): Promise; diff --git a/lib/appium-driver.ts b/lib/appium-driver.ts index ca039d2..3b7b87e 100644 --- a/lib/appium-driver.ts +++ b/lib/appium-driver.ts @@ -1042,6 +1042,7 @@ export class AppiumDriver { /** * Android ONLY! Input key event via ADB. + * Must be combined with '--relaxed-security' appium flag. When not running in sauceLabs '--ignoreDeviceController' should be added too. * @param keyEvent The event number */ public async adbKeyEvent(keyEvent: number | AndroidKeyEvent) { From 6923e9d9fce74c9ee6b991020e3f842939cea87d Mon Sep 17 00:00:00 2001 From: SvetoslavTsenov Date: Thu, 3 Oct 2019 13:25:21 +0300 Subject: [PATCH 3/4] chore: bump mobile-devices-controller version --- lib/appium-driver.d.ts | 2 +- lib/appium-driver.ts | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/appium-driver.d.ts b/lib/appium-driver.d.ts index 5746907..c32d76a 100644 --- a/lib/appium-driver.d.ts +++ b/lib/appium-driver.d.ts @@ -37,7 +37,7 @@ export declare class AppiumDriver { readonly isIOS: boolean; readonly driver: any; /** - * Get the storage where test results from image comparison is logged It will be reports/app nam/device name + * Get the storage where test results from image comparison is logged. The path should be reports/app nam/device name */ readonly reportsPath: string; /** diff --git a/lib/appium-driver.ts b/lib/appium-driver.ts index 3b7b87e..e30d196 100644 --- a/lib/appium-driver.ts +++ b/lib/appium-driver.ts @@ -119,7 +119,7 @@ export class AppiumDriver { } /** - * Get the storage where test results from image comparison is logged It will be reports/app nam/device name + * Get the storage where test results from image comparison is logged. The path should be reports/app nam/device name */ get reportsPath() { return this._args.reportsPath; diff --git a/package.json b/package.json index 0a5f2b9..9535a46 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "frame-comparer": "^2.0.1", "glob": "^7.1.0", "inquirer": "^6.2.0", - "mobile-devices-controller": "^5.1.0", + "mobile-devices-controller": "^5.2.0", "wd": "~1.11.3", "webdriverio": "~4.14.0", "yargs": "~12.0.5" From 513449eac729629306ea6b0f4c26a58c07876e4b Mon Sep 17 00:00:00 2001 From: SvetoslavTsenov Date: Thu, 3 Oct 2019 13:32:46 +0300 Subject: [PATCH 4/4] chore: fix method naming --- lib/device-manager.d.ts | 7 ++++++- lib/device-manager.ts | 20 ++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/device-manager.d.ts b/lib/device-manager.d.ts index f0bdbe6..c6c8916 100644 --- a/lib/device-manager.d.ts +++ b/lib/device-manager.d.ts @@ -19,7 +19,12 @@ export declare class DeviceManager implements IDeviceManager { command: string; "args": Array; }): Promise; - static getDensity(args: INsCapabilities, driver: any): Promise; + /** + * Android only + * @param args + * @param driver + */ + static setDensity(args: INsCapabilities, driver: any): Promise; static applyDeviceAdditionsSettings(driver: any, args: INsCapabilities, sessionInfo: any): Promise; getPackageId(device: IDevice, appPath: string): string; private static cleanUnsetProperties; diff --git a/lib/device-manager.ts b/lib/device-manager.ts index 50e7d0e..63d3105 100644 --- a/lib/device-manager.ts +++ b/lib/device-manager.ts @@ -174,7 +174,7 @@ export class DeviceManager implements IDeviceManager { apiLevel: platformVersion || args.appiumCaps.platformVersion, config: { "density": args.appiumCaps.density, "offsetPixels": args.appiumCaps.offsetPixels } } - + DeviceManager.cleanUnsetProperties(device); return device; @@ -240,7 +240,12 @@ export class DeviceManager implements IDeviceManager { return output; } - public static async getDensity(args: INsCapabilities, driver) { + /** + * Android only + * @param args + * @param driver + */ + public static async setDensity(args: INsCapabilities, driver) { args.device.config = args.device.config || {}; if (args.appiumCaps.platformName.toLowerCase() === "android") { if (!args.ignoreDeviceController) { @@ -256,15 +261,6 @@ export class DeviceManager implements IDeviceManager { if (args.device.config.density) { args.device.config['offsetPixels'] = AndroidController.calculateScreenOffset(args.device.config.density); } - } else { - IOSController.getDevicesScreenInfo().forEach((v, k, m) => { - if (args.device.name.includes(k)) { - args.device.config = { - density: args.device.config['density'] || v.density, - offsetPixels: v.actionBarHeight * (args.device.config['density'] || v.density) - }; - } - }); } } @@ -290,7 +286,7 @@ export class DeviceManager implements IDeviceManager { } if (!density && !args.isIOS) { - await DeviceManager.getDensity(args, driver); + await DeviceManager.setDensity(args, driver); density = args.device.config.density args.device.config['offsetPixels'] = AndroidController.calculateScreenOffset(args.device.config.density); }