diff --git a/lib/appium-driver.d.ts b/lib/appium-driver.d.ts index 218e72a..22494f0 100644 --- a/lib/appium-driver.d.ts +++ b/lib/appium-driver.d.ts @@ -265,8 +265,8 @@ export declare class AppiumDriver { */ getScreenActualViewPort(): IRectangle; /** - * Get screen view port - * This is convenient to use for some gestures on the screen + * Get screen view port. + * Provides the view port that is needed for some gestures like swipe etc. */ getScreenViewPort(): IRectangle; /** diff --git a/lib/appium-driver.ts b/lib/appium-driver.ts index 14f25ed..57ad452 100644 --- a/lib/appium-driver.ts +++ b/lib/appium-driver.ts @@ -1001,22 +1001,27 @@ export class AppiumDriver { * Useful for image comparison */ public getScreenActualViewPort(): IRectangle { - return (this._args.appiumCaps && this._args.appiumCaps.viewportRect) || this._args.device.viewportRect; + return (this._args.device.viewportRect || this.imageHelper.options.cropRectangle); } /** - * Get screen view port - * This is convenient to use for some gestures on the screen + * Get screen view port. + * Provides the view port that is needed for some gestures like swipe etc. */ public getScreenViewPort(): IRectangle { - const rect = (this._args.appiumCaps && this._args.appiumCaps.viewportRect) || this._args.device.viewportRect; - if (rect && Object.getOwnPropertyNames(rect).length > 0) { + const rect = this.getScreenActualViewPort(); + if (rect + && Object.getOwnPropertyNames(rect).length > 0 + && this._args.appiumCaps.device.deviceScreenDensity) { return { x: rect.x / this._args.appiumCaps.device.deviceScreenDensity, y: rect.y / this._args.appiumCaps.device.deviceScreenDensity, - width: rect.x / this._args.appiumCaps.device.deviceScreenDensity, - height: rect.x / this._args.appiumCaps.device.deviceScreenDensity, + width: rect.width / this._args.appiumCaps.device.deviceScreenDensity, + height: rect.height / this._args.appiumCaps.device.deviceScreenDensity, } + } else { + logError("Device's density is undefined!"); + return rect; } } diff --git a/lib/parser.d.ts b/lib/parser.d.ts index 40edb2e..386ae5d 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: any, 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: import("mobile-devices-controller/lib/device").IDevice, driverConfig: any, logImageTypes: LogImageType[], appiumCaps: any; diff --git a/lib/ui-element.ts b/lib/ui-element.ts index 654bbca..47646f5 100644 --- a/lib/ui-element.ts +++ b/lib/ui-element.ts @@ -2,7 +2,7 @@ import { Point } from "./point"; import { Direction } from "./direction"; import { INsCapabilities } from "./interfaces/ns-capabilities"; import { AutomationName } from "./automation-name"; -import { calculateOffset, adbShellCommand } from "./utils"; +import { calculateOffset, adbShellCommand, logError } from "./utils"; import { AndroidKeyEvent } from "mobile-devices-controller"; export class UIElement { @@ -249,7 +249,7 @@ export class UIElement { actRect.width *= density; actRect.height *= density; } else { - throw new Error("Device's density is undefined!"); + logError("Device's density is undefined!"); } return actRect; } diff --git a/package.json b/package.json index f53c94d..901be07 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.0.0", "wd": "~1.11.3", "webdriverio": "~4.14.0", "yargs": "~12.0.5"