website/docs/visual-testing/method-options.md
Methods options are the options that can be set per method. If the option has the same key as an option that has been set during the instantiation of the plugin, this method option will override the plugin option value.
:::info NOTE
save*-methods, but can also be used with the check*-methods:::
hideScrollBarsbooleantrueHide scrollbar(s) in the application. If set to true all scrollbar(s) will be disabled before taking a screenshot. This is set to default true to prevent extra issues.
await browser.saveScreen(
'sample-tag',
{
hideScrollBars: false
}
)
disableBlinkingCursorbooleanfalseEn/Disable all input, textarea, [contenteditable] caret "blinking" in the application. If set to true the caret will be set to transparent before taking a screenshot
and reset when done.
await browser.saveScreen(
'sample-tag',
{
disableBlinkingCursor: true
}
)
disableCSSAnimationbooleanfalseEn/Disable all CSS animations in the application. If set to true all animations will be disabled before taking a screenshot
and reset when done
await browser.saveScreen(
'sample-tag',
{
disableCSSAnimation: true
}
)
enableLayoutTestingbooleanfalseThis will hide all text on a page so only the layout will be used for comparison. Hiding will be done by adding the style 'color': 'transparent !important' to each element.
For the output see Test Output.
:::info
By using this flag each element that contains text (so not only p, h1, h2, h3, h4, h5, h6, span, a, li, but also div|button|..) will get this property. There is no option to tailor this.
:::
await browser.saveScreen(
'sample-tag',
{
enableLayoutTesting: true
}
)
enableLegacyScreenshotMethodbooleanfalseUse this option to switch back to the "older" screenshot method based on the W3C-WebDriver protocol. This can be helpful if your tests rely on existing baseline images or if you're running in environments that don't fully support the newer BiDi-based screenshots. Note that enabling this may produce screenshots with slightly different resolution or quality.
await browser.saveScreen(
'sample-tag',
{
enableLegacyScreenshotMethod: true
}
)
ignoreRegionPaddingnumber1Padding in device pixels added to each side of ignore regions, making each region 2× this value wider and taller. This helps avoid 1 px boundary differences that can appear on high-DPR displays or with the BiDi screenshot protocol. Set to 0 to disable.
await browser.saveScreen(
'sample-tag',
{
ignoreRegionPadding: 0
}
)
waitForFontsLoadedbooleantrueFonts, including third-party fonts, can be loaded synchronously or asynchronously. Asynchronous loading means that fonts might load after WebdriverIO determines that a page has fully loaded. To prevent font rendering issues, this module, by default, will wait for all fonts to be loaded before taking a screenshot.
await browser.saveScreen(
'sample-tag',
{
waitForFontsLoaded: true
}
)
hideElementsarrayThis method can hide 1 or multiple elements by adding the property visibility: hidden to them by providing an array of elements.
await browser.saveScreen(
'sample-tag',
{
hideElements: [
await $('#element-1'),
await $('#element-2'),
]
}
)
removeElementsarrayThis method can remove 1 or multiple elements by adding the property display: none to them by providing an array of elements.
await browser.saveScreen(
'sample-tag',
{
removeElements: [
await $('#element-1'),
await $('#element-2'),
]
}
)
resizeDimensionsobject{ top: 0, right: 0, bottom: 0, left: 0}saveElement or checkElementAn object that needs to hold a top, right, bottom and left amount of pixels that need to make the element cutout bigger.
await browser.saveElement(
'sample-tag',
{
resizeDimensions: {
top: 50,
left: 100,
right: 10,
bottom: 90,
},
}
)
biDiOrigin'document' | 'viewport''document'saveElement or checkElementBiDi-only option that controls which coordinate origin is used when capturing element screenshots via the WebDriver BiDi protocol.
'document' (default): renders the document layout. Works for any element position but does not capture composited layers (e.g. scrollbars, fixed/sticky overlays, will-change elements).'viewport': captures the composited frame as painted, including scrollbars and overlays. Requires the element to be fully visible in the viewport, throws a descriptive error when the element is outside or larger than the viewport.await browser.saveElement(
await $('#my-element'),
'sample-tag',
{
biDiOrigin: 'viewport'
}
)
userBasedFullPageScreenshotbooleanfalsesaveFullPageScreen, saveTabbablePage, checkFullPageScreen or checkTabbablePageWhen set to true, this option enables the scroll-and-stitch strategy to capture full-page screenshots.
Instead of using the browser's native screenshot capabilities, it scrolls through the page manually and stitches multiple screenshots together.
This method is especially useful for pages with lazy-loaded content or complex layouts that require scrolling to fully render.
await browser.saveScreen(
'sample-tag',
{
userBasedFullPageScreenshot: true
}
)
fullPageScrollTimeoutnumber1500saveFullPageScreen or saveTabbablePageThe timeout in milliseconds to wait after a scroll. This might help identify pages with lazy loading.
NOTE: This only works when
userBasedFullPageScreenshotis set totrue
await browser.saveFullPageScreen(
'sample-tag',
{
fullPageScrollTimeout: 3 * 1000
}
)
hideAfterFirstScrollarraysaveFullPageScreen or saveTabbablePageThis method will hide one or multiple elements by adding the property visibility: hidden to them by providing an array of elements.
This will be handy when a page for example holds sticky elements that will scroll with the page if the page is scrolled but will give an annoying effect when a full-page screenshot is made
NOTE: This only works when
userBasedFullPageScreenshotis set totrue
await browser.saveFullPageScreen(
'sample-tag',
{
hideAfterFirstScroll: [
await $('#element-1'),
await $('#element-2'),
]
}
)
Compare options are options that influence the way the comparison, by ResembleJS is being executed.
ignoreColorsbooleanfalseEven though the images are in color, the comparison will compare 2 black/white images
await browser.checkScreen(
'sample-tag',
{
ignoreColors: true
}
)
ignoreAlphabooleanfalseCompare images and discard alpha.
await browser.checkScreen(
'sample-tag',
{
ignoreAlpha: true
}
)
ignoreAntialiasingbooleanfalseCompare images and discard anti-aliasing.
await browser.checkScreen(
'sample-tag',
{
ignoreAntialiasing: true
}
)
ignoreLessbooleanfalseCompare images and compare with red = 16, green = 16, blue = 16, alpha = 16, minBrightness=16, maxBrightness=240
await browser.checkScreen(
'sample-tag',
{
ignoreLess: true
}
)
ignoreNothingbooleanfalseCompare images and compare with red = 0, green = 0, blue = 0, alpha = 0, minBrightness=0, maxBrightness=255
await browser.checkScreen(
'sample-tag',
{
ignoreNothing: true
}
)
scaleImagesToSameSizebooleanfalseScales 2 images to the same size before execution of comparison. Highly recommended to enable ignoreAntialiasing and ignoreAlpha
await browser.checkScreen(
'sample-tag',
{
scaleImagesToSameSize: true
}
)
blockOutStatusBarbooleantrueAutomatically block out the status and address bar during comparisons. This prevents failures on time, wifi or battery status.
await browser.checkScreen(
'sample-tag',
{
blockOutStatusBar: true
}
)
blockOutToolBarbooleantrueAutomatically block out the toolbar.
await browser.checkScreen(
'sample-tag',
{
blockOutToolBar: true
}
)
blockOutSideBarbooleantruecheckScreen(). This is iPad onlyAutomatically block out the sidebar for iPads in landscape mode during comparisons. This prevents failures on the tab/private/bookmark native component.
await browser.checkScreen(
'sample-tag',
{
blockOutSideBar: true
}
)
blockOutarrayAn array of rectangular areas to block out before comparison. Each entry must be an object with x, y, width, and height values (in pixels). The blocked-out areas are painted over before the diff is calculated, preventing those regions from contributing to the mismatch percentage.
await browser.checkScreen(
'sample-tag',
{
blockOut: [
{ x: 0, y: 0, width: 100, height: 50 },
{ x: 300, y: 200, width: 80, height: 80 },
]
}
)
ignorearraycheckScreen-method, NOT with the checkElement-methodThis method will automatically blockout elements or an area on a screen based on an array of elements or an object of x|y|width|height.
await browser.checkScreen(
'sample-tag',
{
ignore: [
$('~element-1'),
await $('~element-2'),
{
x: 150,
y: 250,
width: 100,
height: 100,
}
]
}
)
rawMisMatchPercentagebooleanfalseIf true the return percentage will be like 0.12345678, default is 0.12
await browser.checkScreen(
'sample-tag',
{
rawMisMatchPercentage: true
}
)
returnAllCompareDatabooleanfalseThis will return all compare data, not only the mismatch percentage, see also Console Output
await browser.checkScreen(
'sample-tag',
{
returnAllCompareData: true
}
)
saveAboveTolerancenumber0Allowable value of misMatchPercentage that prevents saving images with differences
await browser.checkScreen(
'sample-tag',
{
saveAboveTolerance: 0.25
}
)
diffPixelBoundingBoxProximitynumber5The pixel proximity used to group diff pixels together in JSON reports. Higher values group more pixels into fewer bounding boxes; lower values produce more accurate but more numerous boxes. Only relevant when createJsonReportFiles is enabled.
await browser.checkScreen(
'sample-tag',
{
diffPixelBoundingBoxProximity: 10
}
)
The baseline folder and screenshot folders(actual, diff) are options that can be set during the instantiation of the plugin or method. To set the folder options on a particular method, pass in folder options to the methods option object. This can be used for:
import path from 'node:path'
const methodOptions = {
actualFolder: path.join(process.cwd(), 'customActual'),
baselineFolder: path.join(process.cwd(), 'customBaseline'),
diffFolder: path.join(process.cwd(), 'customDiff'),
}
// You can use this for all methods
await expect(
await browser.checkFullPageScreen("checkFullPage", methodOptions)
).toEqual(0)
actualFolderstringFolder for the snapshot that has been captured in the test.
baselineFolderstringFolder for the baseline image that is being used to compare against.
diffFolderstringFolder for the image difference rendered by ResembleJS.