Skip to content

fix(ios): ios13 statusbar height #265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/appium-driver.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/**
Expand Down
35 changes: 25 additions & 10 deletions lib/appium-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
DeviceController,
IDevice,
DeviceType,
AndroidController
AndroidController,
IOSController
} from "mobile-devices-controller";
import {
addExt,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)) || "{}") + '');
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 <IRectangle>{
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;
}
}
Expand Down
9 changes: 7 additions & 2 deletions lib/device-manager.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ export declare class DeviceManager implements IDeviceManager {
static getInstalledApps(device: IDevice): Promise<string[]>;
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<void>;
static executeShellCommand(driver: any, commandArgs: {
command: string;
"args": Array<any>;
}): Promise<any>;
static getDensity(args: INsCapabilities, driver: any): Promise<void>;
/**
* Android only
* @param args
* @param driver
*/
static setDensity(args: INsCapabilities, driver: any): Promise<void>;
static applyDeviceAdditionsSettings(driver: any, args: INsCapabilities, sessionInfo: any): Promise<void>;
getPackageId(device: IDevice, appPath: string): string;
private static cleanUnsetProperties;
Expand Down
22 changes: 9 additions & 13 deletions lib/device-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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
};
}
});
}
}

Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/parser.d.ts
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down