Puppetry
3.2.2
3.2.2
  • Welcome Puppetry
  • Getting Started
  • Project
  • Suite
  • Group
  • Target
    • Simple Target
    • iFrame Target
    • ShadowDOM Target
    • Chained Target
    • Shared Target
  • Test Case
  • Test Step / Action
    • Page Commands
    • Page Assertions
    • Target Commands
    • Target Assertions
  • Managing Records
  • Snippets
  • Running tests
    • Interactive Mode
    • Troubleshooting
  • Test Report
  • Export
    • Exporting as Jest Project (CI-friendly)
    • Exporting as Test Specification
  • Settings
  • Template Expressions
  • Testing Techniques
    • Testing Dynamic Content
    • Exhaustive Testing
    • Performance Testing
    • Visual Regression Testing
    • Testing Shadow DOM
    • Testing Google Analytics tracking code
    • Testing Chrome Extensions
    • Testing REST API
    • Mocking HTTP/S Requests
    • Testing Transactional Emails
      • Example with Restmail.net
      • Example with Mailinator
      • Example with IMAP bridge
      • Example with Google API
    • Testing Forms with Captcha
  • Version Control
  • Tips and Tricks
    • Embrace the Power of CSS
  • Command API
  • Test Application
Powered by GitBook
On this page

Was this helpful?

  1. Testing Techniques

Visual Regression Testing

PreviousPerformance TestingNextTesting Shadow DOM

Last updated 5 years ago

Was this helpful?

CSS like any other source code needs refactoring. We work to improve code readability and reusability, to make CSS faster to execute. We try alternative solutions (like switching from flexbox to grid). As we are done with the code changes we need to ensure the app’s “look & feel” didn’t alter. It can turn out quite a challenge if do it manually – the app may consist of dozens of pages that need to be tested for every defined viewport breakpoint. Here you can take advantage of Puppetry. All what you need to do is to create tests visiting app pages for given breakpoint viewports and call page.assertScreenshot or TARGET.assertScreenshot method.

Just before starting refactoring we run the tests with "update comparison images" flag on.

Since we have no assertions the report is "green". However during the run Puppetry creates screenshots of every requested page (or target) and keeps them as original for further comparison.

Now we can do the refactoring. In order to see how it really works we are going to consider a case were refactoring breaks the existing styles.

Well, let's say we has the following styles applied to the heading in banner section:

body {
  color: white;
}
.banner h1 {
  font-size: 48px;
}

During refactoring we decided that general rule for typography would be:

h1 {
  color: black;
}

Thus we didn't think that it would also apply for banner heading, which inherits currently color from body.

So we run the test and this time with "update comparison images" set off.

The test report informs about a failure. It also provides the expected (original) screenshot and the actual and tries to build a diff image.

CSS regression test case
Update comparison images checkbox is on
Test report
Update comparison images checkbox is off
CSS regression test report
Diff image