appium-uiautomator2-driver
Version:
UiAutomator2 integration for Appium
66 lines • 2.03 kB
JavaScript
/**
* Gets the status bar height in pixels.
* @returns The status bar height in pixels.
*/
export 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.
*/
export 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.
*/
export 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).
*/
export async function mobileViewPortRect() {
return await this.getViewPortRect();
}
/**
* Gets the window rectangle (W3C endpoint).
* @returns The window rectangle (x, y, width, height).
*/
export 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.
*/
export async function getDisplayDensity() {
return (await this.uiautomator2.jwproxy.command('/appium/device/display_density', 'GET', {}));
}
/**
* Gets the window size.
* @returns The window size (width, height).
*/
export async function getWindowSize() {
return (await this.uiautomator2.jwproxy.command('/window/current/size', 'GET', {}));
}
//# sourceMappingURL=viewport.js.map