Перейти к основному содержимому

assertView

Обзор

Используйте команду assertView, чтобы снять скриншот элемента для определенного состояния теста и сравнить его с эталонным.

к сведению

Эта команда реализована внутри Testplane, в API WebDriverIO её нет.

Использование

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

Во время выполнения команда assertView вызывает waitForExist с waitTimeout и waitInterval.

Параметры команды

ИмяТипОписание
stateStringОбязательный параметр. Название состояния теста. Должно быть уникальным в пределах одного теста.
optionsObjectНастройки команды assertView.

state

Обязательный параметр. Задает название состояния теста. Название должно быть уникальным в пределах одного теста.

options

Задает настройки команды assertView:

OptionTypeDescription
ignoreElementsArray or String

Elements (specified as selectors) that will be ignored when comparing screenshots. Ignoring is implemented by painting the listed elements black. In the case of a single element, the parameter can be specified as a string.

toleranceNumberSensitivity to color differences.
antialiasingToleranceNumberSensitivity to antialiasing.
allowViewportOverflowBoolean

By default, Testplane throws an error if an element is outside the viewport boundaries. This parameter disables boundary checking, allowing screenshots of elements that do not fit within the viewport. Only the parts of the element that fit within the viewport will be visible in the screenshot. However, if compositeImage is set to true, parts of the element that are below the viewport will also be visible in the screenshot. Similarly, if captureElementFromTop is set to true, parts of the element that are above the viewport will also be included in the screenshot.

captureElementFromTopBoolean

Capture a screenshot of the element from the very top. If the element is outside the viewport, it will be scrolled into view.

compositeImageBoolean

If the element does not fit within the viewport, enabling this option will take multiple screenshots of different parts of the element sequentially, and then stitch them together into one image to display the entire element.

screenshotDelayNumber

Delay in milliseconds before taking a screenshot. This can be useful when there are elements on the page that use animation, or a scrollbar that does not disappear immediately and ends up in the resulting screenshot.

selectorToScrollString

Selector to scroll. This can be useful when you need to take a screenshot of a modal window that does not fit on the screen. Otherwise, without specifying the selector, the scroll will be applied to the window object, and the background will scroll, leaving the popup window in place.

disableAnimationBoolean

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

ignoreDiffPixelCount`${number}%` or 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.

Примеры использования

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");
});