Skip to content

Commit 0d7d101

Browse files
fix: prevent crashing in case device density is missing (#256)
* fix: prevent crashing in case device density is missing * update mobile-devices-controller version
1 parent 0d832c4 commit 0d7d101

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

Diff for: lib/appium-driver.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ export declare class AppiumDriver {
265265
*/
266266
getScreenActualViewPort(): IRectangle;
267267
/**
268-
* Get screen view port
269-
* This is convenient to use for some gestures on the screen
268+
* Get screen view port.
269+
* Provides the view port that is needed for some gestures like swipe etc.
270270
*/
271271
getScreenViewPort(): IRectangle;
272272
/**

Diff for: lib/appium-driver.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -1001,22 +1001,27 @@ export class AppiumDriver {
10011001
* Useful for image comparison
10021002
*/
10031003
public getScreenActualViewPort(): IRectangle {
1004-
return <IRectangle>(this._args.appiumCaps && this._args.appiumCaps.viewportRect) || this._args.device.viewportRect;
1004+
return <IRectangle>(this._args.device.viewportRect || this.imageHelper.options.cropRectangle);
10051005
}
10061006

10071007
/**
1008-
* Get screen view port
1009-
* This is convenient to use for some gestures on the screen
1008+
* Get screen view port.
1009+
* Provides the view port that is needed for some gestures like swipe etc.
10101010
*/
10111011
public getScreenViewPort(): IRectangle {
1012-
const rect = (this._args.appiumCaps && this._args.appiumCaps.viewportRect) || this._args.device.viewportRect;
1013-
if (rect && Object.getOwnPropertyNames(rect).length > 0) {
1012+
const rect = this.getScreenActualViewPort();
1013+
if (rect
1014+
&& Object.getOwnPropertyNames(rect).length > 0
1015+
&& this._args.appiumCaps.device.deviceScreenDensity) {
10141016
return <IRectangle>{
10151017
x: rect.x / this._args.appiumCaps.device.deviceScreenDensity,
10161018
y: rect.y / this._args.appiumCaps.device.deviceScreenDensity,
1017-
width: rect.x / this._args.appiumCaps.device.deviceScreenDensity,
1018-
height: rect.x / this._args.appiumCaps.device.deviceScreenDensity,
1019+
width: rect.width / this._args.appiumCaps.device.deviceScreenDensity,
1020+
height: rect.height / this._args.appiumCaps.device.deviceScreenDensity,
10191021
}
1022+
} else {
1023+
logError("Device's density is undefined!");
1024+
return rect;
10201025
}
10211026
}
10221027

Diff for: lib/parser.d.ts

+1-1
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: any, 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: import("mobile-devices-controller/lib/device").IDevice, driverConfig: any, logImageTypes: LogImageType[], appiumCaps: any;

Diff for: lib/ui-element.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Point } from "./point";
22
import { Direction } from "./direction";
33
import { INsCapabilities } from "./interfaces/ns-capabilities";
44
import { AutomationName } from "./automation-name";
5-
import { calculateOffset, adbShellCommand } from "./utils";
5+
import { calculateOffset, adbShellCommand, logError } from "./utils";
66
import { AndroidKeyEvent } from "mobile-devices-controller";
77

88
export class UIElement {
@@ -249,7 +249,7 @@ export class UIElement {
249249
actRect.width *= density;
250250
actRect.height *= density;
251251
} else {
252-
throw new Error("Device's density is undefined!");
252+
logError("Device's density is undefined!");
253253
}
254254
return actRect;
255255
}

Diff for: package.json

+1-1
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.0.0",
4040
"wd": "~1.11.3",
4141
"webdriverio": "~4.14.0",
4242
"yargs": "~12.0.5"

0 commit comments

Comments
 (0)