Visual assertions, also known as visual regression tests, are used to detect changes in your UI across test executions via screenshots. In other words, Autify Nexus can tell whether a certain part of your website looks different than it did at the time of recording or the last time a test ran successfully.
Recording a visual assertion step
To record a visual assertion, choose one of the following actions when recording:
Assert page visual change (page assertion)
Looks the same (element assertion)
Max pixel difference (%)
The max pixel difference sets a threshold of acceptable change, literally the difference in pixels, of the target between test executions. Changes beyond the threshold will cause the assertion to fail. 0% is very strict — a pixel perfect test. 100% accepts all changes to the target.
Setting the correct threshold for failing assertions
Depending on your computer’s hardware and software settings, as well as the window size you use during test execution, your visual assertion may not pass on the first test you run after recording. To keep things simple, you can use the screenshot recommended by Autify Nexus by clicking Update expected screenshot in the detailed test result for the failed test. If you use this screenshot, you do not need to adjust the threshold of your assertion. Subsequent tests will pass as long as there is no further change to the target.
If you expect minor changes in your UI, minor rendering differences across test environments, or you want to stabilize an assertion against a complex element, try increasing the threshold in 1 to 5% increments until you find a reasonable level that works for you.