Skip to main content

assertView

Overview

Use the assertView command to take a screenshot of an element for a specific test state and compare it with a reference.

Usage

await browser.$(selector).assertView(state, options);
info

The assertView command uses waitForExist (with waitTimeout and waitInterval) to wait for the element to exist before taking a screenshot.

It also automatically waits for static (fonts, images, etc.) to load using the waitForStaticToLoad command.

Command Parameters

NameTypeDescription
statestring

Required parameter. The name of the test state. It must be unique within a single test.

optionsAssertViewOptsSettings for the assertView command.

state

Required parameter. Specifies the name of the test state. The name must be unique within a single test.

options

Specifies the settings for the assertView command:

OptionTypeDescription
ignoreElementsstring | string[]

Elements (specified as selectors) that will be ignored when comparing screenshots. Ignoring is implemented by painting the listed elements black. If multiple elements match any of the selectors, all matches will be ignored.

tolerancenumberSensitivity to color differences, 3.0 by default. Read more.
antialiasingTolerancenumberSensitivity to antialiasing, 4 by default. Read more.
allowViewportOverflowboolean

By default, Testplane will print a warning if element could not be captured in full, this option disables the warning.

Use this option in combination with captureElementFromTop to disable any scrolling that might happen before capture.

captureElementFromTopboolean

By default, Testplane may scroll the element into view before capturing a screenshot, if it's not visible initially.

If this option is disabled and element is not visible initially, Testplane will throw an error.

compositeImageboolean

By default, Testplane will take capture the element in full by taking multiple screenshots of the element and scrolling, and then stitch them together.

When disabled, only the part of the element that is visible on the first screenshot will be captured.

screenshotDelaynumber

Delay in milliseconds before taking a screenshot.

This can be useful to wait for a scrollbar to disappear before capturing a screenshot.

disableAnimationboolean

Disable animations and transitions when taking a screenshot. Default is true starting from version 8.0.0.

ignoreDiffPixelCountnumber | `${number}%`

Percentage of pixels to ignore in the diff. Useful for ignoring very small diffs.

Default is 0. Available starting from version 8.2.0.

waitForStaticToLoadTimeoutnumber

Default is 5000. Timeout for waitForStaticToLoad command, which is automatically called before taking screenshot.

If value is set to 0, waiting is disabled. Available starting from version 8.32.0.

disableHover"always" | "never" | "when-scrolling-needed"

By default, Testplane will disable hover effects if scrolling is needed to capture element in full.

Available starting from version 9.0.0.

cropMargins{ top?: number, right?: number, bottom?: number, left?: number }

Determines the margins to crop the screenshot by. Useful to crop scrollbars on android emulators.

Available starting from version 9.0.0.

selectorToScrollstring

Deprecated. Starting from Testplane 9, the scrollable element is determined automatically.

Manual override affects what element Testplane will scroll when capturing a screenshot.

Usage Examples

example.js

it("should assert view", async ({ browser }) => {
await browser.url("some/url");

const elem = await browser.$(".button");

await elem.assertView("plain");
await elem.click();
await elem.assertView("clicked");
});

History

VersionChanges
v9.0.0

Major update to the screenshot engine, see full article for more details. Added disableHover and cropMargins options. selectorToScroll is deprecated because the scrollable element is now detected automatically. tolerance is now 3.0 by default instead of 2.3.

v8.32.0Added waitForStaticToLoadTimeout option.
v8.2.0Added ignoreDiffPixelCount option.
v8.0.0disableAnimation defaults to true.