> For the complete documentation index, see [llms.txt](https://help.autify.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.autify.com/nocode-web/en/autify-university/advanced/visual-testing/visual-regression-testing-for-elements.md). Agents can also search and read this documentation through its [MCP server](https://help.autify.com/~gitbook/mcp).

# Visual Regression Testing for Elements

## Overview

In Autify, visual regression testing can be performed on elements. You can add the assertion command `Element should look the same` in a scenario, which compares the current screenshot of the target element and **the reference image created from the past test run**. Any kinds of elements on the screen, images or tables or divs, can be selected for the assertion as long as they can fit in the viewport.

When a test with the `Element should look the same` steps is run, the test will fail if the latest screenshot and the reference image did not match a pixel-by-pixel comparison. In such a case, review the result to see if the difference was caused by an expected change. If that was an expected change, click **Accept changes**. This is all that is required to update the reference image that will be used for the next run!

{% hint style="info" %}
**Note**

Visual Regression Testing for Elements works only on Chrome/Linux environment. When run on other environments, `Element should look the same` steps will be skipped.
{% endhint %}

## Perform Visual Regression Testing for Elements

### Record a scenario

Start recording from the New Scenario page or Scenario Details page. On Autify Recorder, click on the checkbox (☑️) and select the element on which you want to create an assertion. Then, select `Element Should Look The Same` from the assertion commands list.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-292ac76edb9309a5f7423610562fe563a3247b45%2FScreenshot%202024-09-10%20at%2013.52.53.png?alt=media)

When you save the scenario, you will see a new `Element Should Look The Same` step in your scenario. Note that the step has no thumbnail, but it will have a **reference image** after the first run.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-b4aa6faf2fbdbbdeb84926b92370791fddddb329%2FScreen%20Shot%202023-04-11%20at%2015.03.44.png?alt=media)

### Run the test twice

Once ready, run the scenario. During the first run, the `Element Should Look The Same` step is skipped with the following message as there is no **reference image** to compare with yet: *This step is skipped on the first run. reference image is created, and future tests will compare the element with this reference image.*

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-37ea911ebf2971e83ecb5cb99b8ae3b1983377d9%2FScreenshot%202024-09-10%20at%2015.38.11.png?alt=media)

If you look at the step detail of the scenario, you can review the reference image created by the first run.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-316695fad80f8fba41cd2d9380c38323bd0adb22%2FScreenshot%202024-09-10%20at%2014.02.56.png?alt=media)

Next, run the scenario again to perform the assertion. This time, the current image will be compared with the reference image created during the previous successful test run in the "Side by Side" tab at the `Element Should Look The Same` step!

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-17bb4040153ad44467b0819b5c92c181f1bf9327%2FScreenshot%202024-09-10%20at%2015.41.11.png?alt=media)

Open the screenshot of `Element Should Look The Same` to see the side-by-side comparison. By clicking the "Diff" tab, you will be able to see the images of the element compared with the reference image.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-4173356928b4fa10c458c5ea9ebaa34d1aae6608%2FScreenshot%202024-09-10%20at%2014.10.23.png?alt=media)

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-909080a2cf4d226e6c7e9f92c9abe73b3666a539%2FScreenshot%202024-09-10%20at%2014.10.44.png?alt=media)

### Visual Regression Diff Threshold <a href="#visual-regression-diff-threshold" id="visual-regression-diff-threshold"></a>

The Visual Regression Diff Threshold feature allows users to control how much difference between the reference image and the current image is acceptable before a test is marked as failed. This can be found and configured in the step details of the scenario.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-0583eb4c049279def846fa795c35f7eb46af1957%2Fimage2.png?alt=media)

By setting a Diff threshold ranging from 0 to 100, users can specify the maximum percentage of difference allowed for the test to pass.

#### Example

If a threshold of 1% is set, the test will pass as long as the difference (Diff score) between the images is 1% or less. If the Diff score exceeds the threshold, the test will fail, indicating a more significant visual change.

**Success**

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-8401534855ad4679dd83455c271f3d4afe85b481%2FScreenshot%202024-09-10%20at%2015.52.08.png?alt=media)

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-e17235e2f80a2e08ef2082691c8868faaf016042%2FScreenshot%202024-09-10%20at%2014.51.56.png?alt=media)

**Fail**

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-61812992e659c03f12f22f9d1be33a6ee172de5f%2FScreenshot%202024-09-10%20at%2015.56.44.png?alt=media)

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-efd7f542605ebc6bed25495c9951e970d68220b7%2FScreenshot%202024-09-10%20at%2015.06.44\(1\).png?alt=media)

This feature is especially useful for reducing false positives caused by minor, irrelevant changes in visual appearance. It provides greater flexibility in determining what is acceptable in a visual regression test.

### Accept changes <a href="#accept-changes" id="accept-changes"></a>

The `Element Should Look The Same` step passes when the current screenshot either exactly matches the reference image or falls within the set Diff threshold. Otherwise, the step fails. The following screenshot shows the failure of a `Element Should Look The Same` step.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-a0f9b2053a741237067e1543af0efc6ffcf4756a%2FScreen%20Shot%202023-04-22%20at%206.47.08\(1\).png?alt=media)

However, there will be times when you will want to accept the change in appearance and use this result as the reference image in the future. That's why we have an "Accept changes" button.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-c27fd1a75f128878061ecaa4a15f6b24c3b23512%2Fimage1.png?alt=media)

When you click this button, the reference image for this `Element Should Look The Same` step will be updated, although it won't affect the status of the test result itself.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-e3cb7a3fcc9f41ad680084e5072e71c130ce42d0%2FScreenshot%202024-09-10%20at%2015.32.57.png?alt=media)

The next time you run the test, the new reference image will be used for the comparison. It is easy to change the expected appearance of the element.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-a43d656f38ec69f6590dfcbdf655f53ccd51f8a7%2FScreen%20Shot%202023-04-22%20at%206.57.46.png?alt=media)

## Notes on use

### Make assertions against text

You can use this feature to make assertions against text, but Autify may detect minute differences that occur due to font rendering, causing the assertion step to fail. Therefore, if you wish to make assertions against text, we recommend that you use [text assertion](https://help.autify.com/nocode-web/en/autify-university/advanced/assertions-1/assertion-elements-on-the-page.md) such as the "Element Text Should Be" command.

### Make assertions against colors

While you can use this feature to make assertions against colors, Autify might miss changes in colors depending on the type of color change, resulting in a successful step even when there is a change. We recommend using JS steps for color assertions.

* [Confirm an element has style](https://javascript-snippets.autify.com/snippets/assertions/assert_style/)

### Duplicate a scenario

When a scenario is duplicated, the reference image for this feature is also duplicated.

### Use in a Step Group

When this feature is used within a Step Group, the Step Group itself maintains the reference image. If the reference image for the target element varies depending on the scenario, we recommend adding the step to the scenario instead of including it in a Step Group.

We hope you enjoy using our visual regression testing feature, and look forward to your feedback!


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.autify.com/nocode-web/en/autify-university/advanced/visual-testing/visual-regression-testing-for-elements.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
