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 513e075..e30d196 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; @@ -117,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; @@ -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,16 +1026,16 @@ 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; } } diff --git a/lib/device-manager.d.ts b/lib/device-manager.d.ts index e535392..c6c8916 100644 --- a/lib/device-manager.d.ts +++ b/lib/device-manager.d.ts @@ -13,13 +13,18 @@ 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; "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 dc51caa..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 - }; - } - }); } } @@ -289,8 +285,8 @@ export class DeviceManager implements IDeviceManager { args.device.config['offsetPixels'] = AndroidController.calculateScreenOffset(args.device.config.density); } - if (!density) { - await DeviceManager.getDensity(args, driver); + if (!density && !args.isIOS) { + await DeviceManager.setDensity(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..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.0.0", + "mobile-devices-controller": "^5.2.0", "wd": "~1.11.3", "webdriverio": "~4.14.0", "yargs": "~12.0.5"