UNPKG

appium-uiautomator2-driver

Version:
75 lines 2.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getStatusBarHeight = getStatusBarHeight; exports.getDevicePixelRatio = getDevicePixelRatio; exports.getViewPortRect = getViewPortRect; exports.mobileViewPortRect = mobileViewPortRect; exports.getWindowRect = getWindowRect; exports.getDisplayDensity = getDisplayDensity; exports.getWindowSize = getWindowSize; /** * Gets the status bar height in pixels. * @returns The status bar height in pixels. */ async function getStatusBarHeight() { const { statusBar } = (await this.uiautomator2.jwproxy.command(`/appium/device/system_bars`, 'GET', {})); return statusBar; } /** * Gets the device pixel ratio. * @returns The device pixel ratio as a string. */ async function getDevicePixelRatio() { return String(await this.uiautomator2.jwproxy.command('/appium/device/pixel_ratio', 'GET', {})); } /** * Gets the viewport rectangle coordinates. * @returns The viewport rectangle (left, top, width, height), accounting for status bar height. */ async function getViewPortRect() { const windowSize = await this.getWindowSize(); const statusBarHeight = await this.getStatusBarHeight(); // android returns the upscaled window size, so to get the true size of the // rect we have to downscale return { left: 0, top: statusBarHeight, width: windowSize.width, height: windowSize.height - statusBarHeight, }; } /** * Returns the viewport coordinates. * @returns The viewport rectangle (left, top, width, height). */ async function mobileViewPortRect() { return await this.getViewPortRect(); } /** * Gets the window rectangle (W3C endpoint). * @returns The window rectangle (x, y, width, height). */ async function getWindowRect() { const { width, height } = await this.getWindowSize(); return { width, height, x: 0, y: 0, }; } /** * Gets the display density. * @returns The display density value. */ async function getDisplayDensity() { return (await this.uiautomator2.jwproxy.command('/appium/device/display_density', 'GET', {})); } /** * Gets the window size. * @returns The window size (width, height). */ async function getWindowSize() { return (await this.uiautomator2.jwproxy.command('/window/current/size', 'GET', {})); } //# sourceMappingURL=viewport.js.map