UNPKG

@wdio/image-comparison-core

Version:

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

31 lines (30 loc) 1.18 kB
import afterScreenshot from '../helpers/afterScreenshot.js'; import { DEFAULT_RESIZE_DIMENSIONS } from '../helpers/constants.js'; import { buildAfterScreenshotOptions } from '../helpers/options.js'; import { takeBase64ElementScreenshot } from '../methods/images.js'; /** * Saves an element image for a native app */ export default async function saveAppElement({ browserInstance, instanceData, folders, element, tag, saveElementOptions, isNativeContext = false, }) { // 1. Set some variables const resizeDimensions = saveElementOptions.method.resizeDimensions || DEFAULT_RESIZE_DIMENSIONS; const { devicePixelRatio, isIOS } = instanceData; // 2. Take the screenshot const base64Image = await takeBase64ElementScreenshot({ browserInstance, element: element, devicePixelRatio, isIOS, resizeDimensions, }); // 3. Return the data const afterOptions = buildAfterScreenshotOptions({ base64Image, folders, tag, isNativeContext, instanceData: instanceData, wicOptions: saveElementOptions.wic }); return afterScreenshot(browserInstance, afterOptions); }