Features

Angular Visual Regression Testing

  • Share on Facebook
  • Share on Twitter
  • Share on LinkedIn
  • Share on HackerNews

Visual Comparison Testing with Angular, together with the power of Cypress, is a good method to improve your test suite.

By taking screenshots of your Angular app, you can compare your UI with baseline images. If a screenshot is different from the original screenshot, a (visual) bug could have slipped in your UI.

Using the extensive browser grid of TestingBot, it's possible to test your Angular UI on various browsers and platforms.

Advantages of Visual Comparison Testing

Visual UI testing is a method of taking screenshots, comparing these to baseline images and triggering an error when there's a difference detected.


UI testing can be used as part of your test suite in your CI/CD environment, next to functional tests, unit tests and more.

There are several advantages to using Visual Comparison Testing. Below are the most popular advantages.

  • Automation:

    These tests are done automatically, which means they can be repeated whenever you want and how many times you like. In combination with a CI/CD system, this is much more efficient than going through every UI change manually.

  • Quality:

    A pixel comparison algorithm will detect the slightest UI change. Compared with a human tester, the algorithm will detect changes faster and more efficient.

  • Scalability:

    Because this is an automated verification, you can choose to run the algorithm in parallel on a wide variety of configurations. You can choose to run the checks on different viewport sizes, screen resolutions, operating systems, browsers and (mobile) devices.

Angular Visual Regression Testing with Cypress

Cypress is a popular test framework, used by developers and QA to write tests in clear syntax.
With the power of plugins, Cypress can be extended with various enhancements to improve your test suite.

One plugin is called cypress-image-snapshot which allows you to take screenshots during a Cypress test.


Under the hood, the plugin uses the jest-image-snapshot image diffing logic, which uses pixelmatch under the hood.

Once you've used Angular to create your website, you can use Cypress to test the webpages on a variety of browsers, versions and devices.

Angular Visual UI Testing Example

To get started, let's assume that you have an existing Angular project that you want to test visually. If you don't have an Angular project, you can create one using the Angular CLI by running the following command:

ng new demo-app

Once you have an Angular project, you can add Cypress and cypress-image-snapshot to your project by running the following commands:

npm install cypress cypress-image-snapshot --save-dev

Now that you have Cypress and cypress-image-snapshot installed, you can start writing visual UI tests. Below is an example on how to do visual UI testing with Cypress and cypress-image-snapshot:

describe('Visual UI testing', () => {
  it('should check the main page', () => {
    cy.visit('https:/testingbot.com/')
    cy.wait(500) // Wait for UI to settle

    cy.get('body').toMatchImageSnapshot() // Verify screenshot

  })
})

The first time that you will run this test, Cypress will take a screenshot of the entire page and save it as a baseline image. On the next run, Cypress will take another screenshot and compare it to the baseline image. If differences are detected, the Cypress test will fail and display a visual diff of the two images. The diff is useful to visually compare what has changed.

Using Cypress in combination with cypress-image-snapshot for visual UI testing is a useful method to ensure that your Angular application's UI remains consistent and bug free.

Visual UI testing can be very beneficial early in the development process, to make sure any visual defects are detected early.

  • Share on Facebook
  • Share on Twitter
  • Share on LinkedIn
  • Share on HackerNews
TestingBot Logo

Sign up for a Free Trial

Start testing your apps with TestingBot.

No credit card required.

Other Articles

Visual Regression Testing with Python

Find out how to do automated visual UI testing with the power of Python and TestingBot.

Read more
Android Espresso Tutorial

Learn more about Android Espresso Testing in this tutorial.

Read more
Page Object Model (POM) and Page Factory with Appium

Learn more about the Page Object Model and how to use it with Appium.

Read more
Getting Started with Appium

Learn how to use Appium for automated testing. We will provide some tips and tricks, performance optimizations and ways to use Appium Inspector to troubleshoot your native mobile app testing.

Read more
Getting Started with IntelliJ and Selenium WebDriver

A brief overview on how to setup, configure and run Selenium WebDriver tests with IntelliJ IDEA.

Read more
Internationalization testing of websites and mobile apps

Learn more about Internationalization Testing: how to prepare and test your website or mobile app for different regions in the world.

Read more