question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to "mask" areas of the application so visual regression will not be compared against certain parts of the page.

See original GitHub issue

Mode

Page screenshots

Feature description

Use case: If my website has an image carousel and the image content changes routinely or at random, I may want to disregard differences in this section of the website.

Potential solution: A configuration that allows identifiers to be declared for DOM nodes (class, ID, attributes) and sets the CSS property of Visibility with the value of None. Alternatively, if the comparison tool is capable, ignore differences that occur inside certain dom nodes.

This will make specified dom nodes invisible and therefore these elements will not cause false failures in visual regression testing.

Example configuration:

export const config: CustomProjectConfig = {
  pageShots: {
    pages: [
      { id: "capocaccia.dev/posts/uses", path: "/posts/uses", name: "Uses", ignore: ['data-testid="post-cover-image"'] },
      { id: "capocaccia.dev/", path: "/", name: "Home" },
    ],
    pageUrl: "http://172.17.0.1:3000",
  }
};

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

4reactions
chriskalmarcommented, Sep 22, 2022

Just completed implementing the masks feature.

You can see an example in this shot: image

I only provided this mask selector to the page in my list: mask: [{ selector: 'h2' }],

This was enough to mask all H2 elements found on that page.

You can now define for each page a mask list https://github.com/lost-pixel/lost-pixel/blob/feature/shot-mask/src/config.ts#L227

Here are some CSS selector examples: Examples:

  • #my-id: Selects the element with the id my-id
  • .my-class: Selects all elements with the class my-class
  • div: Selects all div elements
  • div.my-class: Selects all div elements with the class my-class
  • li:nth-child(2n): Selects all even li elements
  • [data-testid="hero-banner"]: Selects all elements with the attribute data-testid set to hero-banner
  • div > p: Selects all p elements that are direct children of a div element

In your case the config would look like this:

export const config: CustomProjectConfig = {
  pageShots: {
    pages: [
      {
        path: "/posts/uses",
        name: "Uses",
        mask: [{ selector: '[data-testid="post-cover-image"]' }],
      },
      { path: "/", name: "Home" },
    ],
    pageUrl: "http://172.17.0.1:3000",
  },
};

(I also dropped the id props as they are now obsolete. The name prop defines the uniqueness )

Please upgrade to version 2.20.0 and let me know how it went.

2reactions
Capocacciacommented, Sep 23, 2022

This is an absurd turn around time. Ill upgrade to 2.20.0 and provide feedback.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Feature] Ability to add mask when comparing snapshot images
For example let's say my page always displays a date somewhere on the screen. An image would always see that date as a...
Read more >
Visual regression testing with Playwright - Qxperts
Read on and start coding to do visual regression testing with Playwright. ... in your web application) you can ignore specific sections.
Read more >
Visual Regression Testing. what, why and how - Medium
Essentially, visual regression tests allows us to understand the changes that will be perceived by our users through screenshots and content  ...
Read more >
Visual regression testing and AI: What, why and how? - Ericsson
Visual regression testing, also called user interface (UI) testing, is the process of verifying the aesthetic accuracy of everything end-users ...
Read more >
Visual Regression Testing - Base Web
This is where the visual in "visual snapshot testing" comes from. We use images as our snapshots and compare those images across test...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found