Check settings
Check
generates a screenshot of the current page and adds it to the Applitools Eyes Test.
Syntax
eyes.Check(checkSettings)
Holds the checkpoint's configuration. This is defined using a fluent API, starting with Target
.
Page screenshot
- To take a viewport screenshot, call
Target.Window()
. - To take a full page screenshot, call
Target.Window().Fully()
.
Region screenshot
To take a region screenshot, you can specify either a selector or the element representation itself. For example:
// region by selector
eyes.Check(Target.Region(".banner"));
// region by locator
ILocator locator = page.Locator(".banner");
eyes.Check(Target.Region(locator));
// region by element
await IElementHandle element = page.Locator(".banner").ElementHandleAsync();
eyes.Check(Target.Region(element));
You can specify the absolute coordinates for the required region:
// region by coordinates
eyes.Check(
Target.Region(new Region(10, 20, 200, 80))
);
For all the above options, you can take the entire content of an element that can be scrolled using .Fully()
.
Frames
For taking screenshots of elements inside iframes, you can specify the frame using the Target.Frame
fluent API. For example:
// element inside frame
eyes.Check(
Target.Frame("frame-1").Region(".element-inside frame")
);
To take a screenshot of the entire frame:
// entire frame
eyes.Check(
Target.Frame("frame-1").Fully()
);
To create a "frame chain" with multiple calls:
// element inside nested frames
eyes.Check(
Target.Frame("frame-1").Frame("frame-1-1").Region(".nested-element")
)
Ignore regions
The test will not report any mismatches in an ignore region. This is useful for example for areas on the screen whose content is different on every run such as a time of day field.
// single region
eyes.Check(
"viewport screenshot with ignore region",
Target.Window()
.Ignore(".dynamic-content-here")
)
// multiple regions
var element = await page.Locator("selector").ElementHandleAsync()
eyes.Check(
"viewport screenshot with ignore region",
Target.Window()
.Ignore(".dynamic-content-here")
.Ignore(page.Locator("selector")) // some Locator
.Ignore(element) // some ElementHandle
.Ignore(new Region(10, 20, 30, 40))
)
Possible input types:
- string (interpreted as css selector)
- locator
- element
- coordinates (
new Region(left, top, width, height)
)
Floating regions
In a Floating Region, the position of a region may move without reporting a mismatch.
// viewport screenshot with floating region
eyes.Check(
Target
.Window()
.Floating(".Floating-area", 10, 10, 10, 10) // up, down, left, right
)
// multiple regions
var element = await page.Locator(".floating-area").ElementHandleAsync()
eyes.Check(
Target
.Window()
.Floating(page.Locator(".floating-area"), 10, 10, 10, 10) // Playwright Locator
.Floating(10, ".floating-area")
.Floating(10, page.Locator(".floating-area")) // up, down, left, right all equal to 10
.Floating(10, element) // up, down, left, right all equal to 10
.Floating(10, new Region(10, 20, 30, 40))
.Floating(new Region(10, 20, 30, 40), 10, 10, 10, 10)
)
Possible input types:
- string (interpreted as css selector)
- ILocator
- IElementHandle
- coordinates (
new Region(left, top, width, height)
)
Region match levels
You can set the following match levels for a region:
- Strict: Detect any mismatch visible to the human eye.
- Ignore colors: Similar to the strict match level but ignores changes in colors.
- Layout: Check only the layout and ignore actual text and graphics.
// viewport screenshot with strict region
eyes.Check(Target.Window().Strict(".some-element"));
// viewport screenshot with ignore colors region
eyes.Check(Target.Window().IgnoreColors(".some-element"));
// viewport screenshot with layout region
eyes.Check(Target.Window().Layout(".some-element"));
// multiple regions
Target.Window().IgnoreColors(region1).IgnoreColors(region2).IgnoreColors(region3);
Target.Window().Strict(region1).Strict(region2).Strict(region3);
Target.Window().Layout(region1).Layout(region2).Layout(region3);
Input Types
- String - Interpreted as a CSS selector.
by
Locator - Defines the region.- Element - Specifies the match level region by passing an element.
- Coordinates (
{left, top, width, height}
) - If you have specific coordinates for the region, you can define it using the left, top, width, and height properties.
Accessibility regions
Defines an accessibility region and its type. The type can be IgnoreContrast
, RegularText
, LargeText
, BoldText
, or GraphicalObject
.
// viewport screenshot with accessibility region
eyes.Check(
Target.Window().Accessibility(".some-element", AccessibilityRegionType.LargeText)
);
// multiple regions is done by chaining the same method
eyes.Check(
Target.Window()
.Accessibility(".element-1", AccessibilityRegionType.LargeText)
.Accessibility(".element-2", AccessibilityRegionType.IgnoreContrast)
.Accessibility(".element-3", AccessibilityRegionType.BoldText)
);
Possible input types:
- string (interpreted as css selector)
- ILocator
- IElementHandle
- coordinates (
new Region(left, top, width, height)
)
Scroll root element
Normally, Eyes selects the most appropriate element to scroll to execute the Fully keyword. You can use the scrollRootElement
element to specify the element to scroll explicitly.
// full page with custom scroll root element
eyes.Check(
Target.Window().Fully().ScrollRootElement(".main-content")
);
Possible input types:
- string (interpreted as css selector)
- ILocator
- IElementHandle
Before capture screenshot
Script that runs after the page is loaded but before capturing the screenshot.
eyes.Check("tag", Target.Window().BeforeRenderScreenshotHook(hook));
Tag (WithName
)
Defines a name for the checkpoint in the Eyes Test Manager. The name may be any string and serves to identify the step to the user in the Test manager.
You can change the tag value without impacting testing in any way since Eyes does not use the tag to identify the baseline step that corresponds to the checkpoint; Eyes matches steps based on their content and position in the sequences of images of the test. See How Eyes compares checkpoints and baseline images for details.
// Tag
eyes.Check(Target.Window().WithName("Main page"));
Lazy loading (LazyLoad
)
You can use the SDK to scroll the entire page, or a specific length of the page, to make sure all lazily loaded assets are on the page before performing a check.
Default values
scrollLength
: 300 pxwaitingTime
: 2000msmaxAmountToScroll
: 15,000 px
// lazy loads with default values
eyes.Check(Target.Window().LazyLoad());
// lazy loads with options specified
eyes.Check(Target.Window().LazyLoad(
new LazyLoadOptions(
scrollLength: 250, // amount of pixels to use for each scroll attempt
waitingTime: 500, // milliseconds to wait in-between each scroll attempt
maxAmountToScroll: 1000 // total pixels of the page to be scrolled
)
));
Possible input types:
- nothing (enables sensible defaults)
- options object (
new LazyLoadOptions(maxAmountToScroll, waitingTime, scrollLength)
)
Other details:
- If an option is omitted, the sensible default for that value will be used
- The SDK will repeatedly scroll the page using the
scrollLength
until either the page cannot be scrolled further or themaxAmountToScroll
has been reached (whichever happens first)
Other checkSettings configuration
HideScrollbars
HideCaret
IgnoreDisplacements
UseDom
EnablePatterns