@wdio/image-comparison-core
Version:
Image comparison core module for @wdio/visual-service - WebdriverIO visual testing framework
35 lines (34 loc) • 1.45 kB
JavaScript
import getElementPositionTopDom from '../clientSideScripts/getElementPositionTopDom.js';
import { getBoundingClientRect } from '../clientSideScripts/getBoundingClientRect.js';
/**
* Get the element position on a Android device
*/
export async function getElementPositionAndroid(browserInstance, element, { deviceRectangles, isAndroidNativeWebScreenshot }) {
// This is the native web screenshot
if (isAndroidNativeWebScreenshot) {
return getElementWebviewPosition(browserInstance, element, { deviceRectangles });
}
// This is the ChromeDriver screenshot
return browserInstance.execute(getBoundingClientRect, element);
}
/**
* Get the element position on a desktop browser
*/
export async function getElementPositionDesktop(browserInstance, element, { innerHeight, screenshotHeight }) {
if (screenshotHeight > innerHeight) {
return browserInstance.execute(getElementPositionTopDom, element);
}
return browserInstance.execute(getBoundingClientRect, element);
}
/**
* Get the element position calculated from the webview
*/
export async function getElementWebviewPosition(browserInstance, element, { deviceRectangles: { viewport: { x, y } } }) {
const { height, width, x: boundingClientX, y: boundingClientY } = (await browserInstance.execute(getBoundingClientRect, element));
return {
height,
width,
x: boundingClientX + x,
y: boundingClientY + y,
};
}