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 1 commit
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
1 change: 0 additions & 1 deletion lib/appium-driver.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
Expand Down
34 changes: 24 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 @@ -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,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 <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;
}
}

/**
* 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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/device-manager.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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;
Expand Down
4 changes: 2 additions & 2 deletions lib/device-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
}
});
Expand Down Expand Up @@ -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);
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.1.0",
"wd": "~1.11.3",
"webdriverio": "~4.14.0",
"yargs": "~12.0.5"
Expand Down