Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5844f86

Browse files
fix(ios): ios13 statusbar height (#265)
* fix(ios): ios13 statusbar height
1 parent 183727e commit 5844f86

File tree

6 files changed

+44
-28
lines changed

6 files changed

+44
-28
lines changed

‎lib/appium-driver.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export declare class AppiumDriver {
3737
readonly isIOS: boolean;
3838
readonly driver: any;
3939
/**
40-
* Get the storage where test results from image comparison is logged It will be reports/app nam/device name
40+
* Get the storage where test results from image comparison is logged. The path should be reports/app nam/device name
4141
*/
4242
readonly reportsPath: string;
4343
/**

‎lib/appium-driver.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
DeviceController,
1212
IDevice,
1313
DeviceType,
14-
AndroidController
14+
AndroidController,
15+
IOSController
1516
} from "mobile-devices-controller";
1617
import {
1718
addExt,
@@ -47,6 +48,7 @@ import { DeviceOrientation } from "./enums/device-orientation";
4748
import { NsCapabilities } from "./ns-capabilities";
4849
import { AutomationName } from "./automation-name";
4950
import { AndroidKeyEvent } from "mobile-devices-controller";
51+
import { setInterval } from "timers";
5052

5153
export class AppiumDriver {
5254
private _defaultWaitTime: number = 5000;
@@ -117,7 +119,7 @@ export class AppiumDriver {
117119
}
118120

119121
/**
120-
* Get the storage where test results from image comparison is logged It will be reports/app nam/device name
122+
* Get the storage where test results from image comparison is logged. The path should be reports/app nam/device name
121123
*/
122124
get reportsPath() {
123125
return this._args.reportsPath;
@@ -215,10 +217,11 @@ export class AppiumDriver {
215217

216218
let hasStarted = false;
217219
let retries = 10;
220+
let sessionInfoDetails;
221+
218222
while (retries > 0 && !hasStarted) {
219223
try {
220224
let sessionInfo;
221-
let sessionInfoDetails;
222225
try {
223226
if (args.sessionId || args.attachToDebug) {
224227
const sessionInfos = JSON.parse(((await getSessions(args.port)) || "{}") + '');
@@ -311,7 +314,19 @@ export class AppiumDriver {
311314
await driver.updateSettings(appiumCapsFromConfig.settings);
312315
}
313316

314-
return new AppiumDriver(driver, wd, webio, args.driverConfig, args);
317+
if (+sessionInfoDetails.statBarHeight === 0
318+
&& sessionInfoDetails.platformName.toLowerCase() === "ios"
319+
&& sessionInfoDetails.platformVersion.startsWith("13")) {
320+
try {
321+
const devicesInfos = IOSController.devicesDisplaysInfos();
322+
const matches = devicesInfos.filter(d => sessionInfoDetails.deviceName.includes(d.deviceType));
323+
const deviceType = matches[matches.length - 1];
324+
args.device.viewportRect.y += deviceType.statBarHeight * deviceType.density;
325+
} catch (error) { }
326+
}
327+
328+
const appiumDriver = new AppiumDriver(driver, wd, webio, args.driverConfig, args);
329+
return appiumDriver;
315330
}
316331

317332
public async updateSettings(settings: any) {
@@ -1011,16 +1026,16 @@ export class AppiumDriver {
10111026
public getScreenViewPort(): IRectangle {
10121027
const rect = this.getScreenActualViewPort();
10131028
if (rect
1029+
&& this.isIOS
10141030
&& Object.getOwnPropertyNames(rect).length > 0
1015-
&& this._args.appiumCaps.device.deviceScreenDensity) {
1031+
&& this._args.device.deviceScreenDensity) {
10161032
return <IRectangle>{
1017-
x: rect.x / this._args.appiumCaps.device.deviceScreenDensity,
1018-
y: rect.y / this._args.appiumCaps.device.deviceScreenDensity,
1019-
width: rect.width / this._args.appiumCaps.device.deviceScreenDensity,
1020-
height: rect.height / this._args.appiumCaps.device.deviceScreenDensity,
1033+
x: rect.x / this._args.device.deviceScreenDensity,
1034+
y: rect.y / this._args.device.deviceScreenDensity,
1035+
width: rect.width / this._args.device.deviceScreenDensity,
1036+
height: rect.height / this._args.device.deviceScreenDensity,
10211037
}
10221038
} else {
1023-
logError("Device's density is undefined!");
10241039
return rect;
10251040
}
10261041
}

‎lib/device-manager.d.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@ export declare class DeviceManager implements IDeviceManager {
1313
static getInstalledApps(device: IDevice): Promise<string[]>;
1414
static getDefaultDevice(args: INsCapabilities, deviceName?: string, token?: string, type?: DeviceType, platformVersion?: number): IDevice;
1515
private static convertViewportRectToIRectangle;
16-
static applyAppiumSessionInfoDetails(args: INsCapabilities, sessionInfoDetails: any): IDevice;
16+
static applyAppiumSessionInfoDetails(args: INsCapabilities, sessionInfoDetails: any): any;
1717
static setDontKeepActivities(args: INsCapabilities, driver: any, value: any): Promise<void>;
1818
static executeShellCommand(driver: any, commandArgs: {
1919
command: string;
2020
"args": Array<any>;
2121
}): Promise<any>;
22-
static getDensity(args: INsCapabilities, driver: any): Promise<void>;
22+
/**
23+
* Android only
24+
* @param args
25+
* @param driver
26+
*/
27+
static setDensity(args: INsCapabilities, driver: any): Promise<void>;
2328
static applyDeviceAdditionsSettings(driver: any, args: INsCapabilities, sessionInfo: any): Promise<void>;
2429
getPackageId(device: IDevice, appPath: string): string;
2530
private static cleanUnsetProperties;

‎lib/device-manager.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export class DeviceManager implements IDeviceManager {
174174
apiLevel: platformVersion || args.appiumCaps.platformVersion,
175175
config: { "density": args.appiumCaps.density, "offsetPixels": args.appiumCaps.offsetPixels }
176176
}
177-
177+
178178
DeviceManager.cleanUnsetProperties(device);
179179

180180
return device;
@@ -240,7 +240,12 @@ export class DeviceManager implements IDeviceManager {
240240
return output;
241241
}
242242

243-
public static async getDensity(args: INsCapabilities, driver) {
243+
/**
244+
* Android only
245+
* @param args
246+
* @param driver
247+
*/
248+
public static async setDensity(args: INsCapabilities, driver) {
244249
args.device.config = args.device.config || {};
245250
if (args.appiumCaps.platformName.toLowerCase() === "android") {
246251
if (!args.ignoreDeviceController) {
@@ -256,15 +261,6 @@ export class DeviceManager implements IDeviceManager {
256261
if (args.device.config.density) {
257262
args.device.config['offsetPixels'] = AndroidController.calculateScreenOffset(args.device.config.density);
258263
}
259-
} else {
260-
IOSController.getDevicesScreenInfo().forEach((v, k, m) => {
261-
if (args.device.name.includes(k)) {
262-
args.device.config = {
263-
density: args.device.config['density'] || v.density,
264-
offsetPixels: v.actionBarHeight
265-
};
266-
}
267-
});
268264
}
269265
}
270266

@@ -289,8 +285,8 @@ export class DeviceManager implements IDeviceManager {
289285
args.device.config['offsetPixels'] = AndroidController.calculateScreenOffset(args.device.config.density);
290286
}
291287

292-
if (!density) {
293-
await DeviceManager.getDensity(args, driver);
288+
if (!density&&!args.isIOS) {
289+
await DeviceManager.setDensity(args, driver);
294290
density = args.device.config.density
295291
args.device.config['offsetPixels'] = AndroidController.calculateScreenOffset(args.device.config.density);
296292
}

‎lib/parser.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
import { LogImageType } from "./enums/log-image-type";
2-
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;
2+
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;

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"frame-comparer": "^2.0.1",
3737
"glob": "^7.1.0",
3838
"inquirer": "^6.2.0",
39-
"mobile-devices-controller": "^5.0.0",
39+
"mobile-devices-controller": "^5.2.0",
4040
"wd": "~1.11.3",
4141
"webdriverio": "~4.14.0",
4242
"yargs": "~12.0.5"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /