UNPKG

@wdio/image-comparison-core

Version:

Image comparison core module for @wdio/visual-service - WebdriverIO visual testing framework

42 lines (41 loc) 1.85 kB
import { takeBase64BiDiScreenshot, takeBase64Screenshot } from './screenshots.js'; import { makeCroppedBase64Image } from './images.js'; import { determineScreenRectangles } from './rectangles.js'; export async function takeWebScreenshot(browserInstance, options, shouldUseBidi = false) { let base64Image; if (shouldUseBidi) { // Take the screenshot with the BiDi method base64Image = await takeBase64BiDiScreenshot({ browserInstance }); } else { // Take the screenshot with the regular method base64Image = await takeBase64Screenshot(browserInstance); // Determine the rectangles const screenRectangleOptions = { devicePixelRatio: options.devicePixelRatio || NaN, enableLegacyScreenshotMethod: options.enableLegacyScreenshotMethod, innerHeight: options.innerHeight || NaN, innerWidth: options.innerWidth || NaN, isAndroidChromeDriverScreenshot: options.isAndroidChromeDriverScreenshot, isAndroidNativeWebScreenshot: options.isAndroidNativeWebScreenshot, isEmulated: options.isEmulated || false, initialDevicePixelRatio: options.initialDevicePixelRatio || NaN, isIOS: options.isIOS, isLandscape: options.isLandscape, }; const rectangles = determineScreenRectangles(base64Image, screenRectangleOptions); // Make a cropped base64 image base64Image = await makeCroppedBase64Image({ addIOSBezelCorners: options.addIOSBezelCorners, base64Image, deviceName: options.deviceName, devicePixelRatio: options.devicePixelRatio || NaN, isIOS: options.isIOS, isLandscape: options.isLandscape, rectangles, }); } return { base64Image, }; }