Table of Contents
What is Percy?
Setting up a Sample Site
Automated Testing with CircleCI
Connecting Percy to CircleCI
Leveraging Percy's Power
Home Web Front-end CSS Tutorial Testing for Visual Regressions with Percy

Testing for Visual Regressions with Percy

Apr 22, 2025 am 11:02 AM

Testing for Visual Regressions with Percy

This post, based on personal experience, isn't sponsored (though we've collaborated with Percy on a sponsored video demonstrating its setup). Percy is a powerful visual review platform, and I highly recommend exploring it.

Imagine this common scenario: Unit tests pass, you merge code, and QA flags a UI issue—a button floating off-screen. You didn't touch that code, but you did change some CSS. Suddenly, you're questioning every UI element across various screen sizes and browsers. Testing manually is a monumental task.

Percy is the solution. It's invaluable for detecting unexpected design and layout changes. It's become essential in my workflow, and I'm sharing how it strengthens code and prevents errors. It integrates seamlessly with other tools and is easy to set up.

What is Percy?

Percy is a comprehensive visual review platform designed to detect visual regressions. Many code changes, especially CSS modifications, can introduce unforeseen design breaks. Percy provides confidence when modifying large stylesheets or legacy code, helping identify all UI elements affected by a single code change.

Setting up a Sample Site

We'll create a simple site for Percy testing using Gatsby and Netlify. While a deep dive into these technologies is beyond this scope, they simplify the setup process, eliminating complex server configurations.

Use a Netlify template and click "Deploy to Netlify." This creates a GitHub repo and deploys the app via Netlify. The result is a live site ready for Percy integration.

Automated Testing with CircleCI

Percy thrives in a CI environment. We'll use CircleCI to trigger tests on each commit.

  1. Clone the Netlify-deployed repo (e.g., git clone https://github.com/PaulRyanStitcherAds/gatsby-starter-netlify-cms.git).
  2. Sign up for CircleCI using your GitHub account.
  3. Add your project in CircleCI, selecting Linux and Ruby (for percy-cli).
  4. Create a .circleci/config.yml file with this configuration:
version: 2
jobs:
  build:
    docker:
      - image: circleci/ruby:2.4.1-node-browsers
    working_directory: ~/repo
    steps:
      - checkout
      - run:
          name: install dependencies
          command: |
            npm install
            gem install percy-cli
      - run:
          name: run tests
          command: |
            npm run build
            percy snapshot public
Copy after login

This installs percy-cli and runs Percy snapshots after the build. (Note: Ensure you don't mistakenly try installing percy-cli as an npm package.)

Push to the master branch to trigger a CircleCI build.

Connecting Percy to CircleCI

  1. Create a Percy account using GitHub.
  2. Create a new organization and project in Percy.
  3. Obtain your Percy token from "Project Settings."
  4. Add the token as an environment variable in CircleCI's "Build Settings."
  5. Run Percy by pushing to master again. Percy will create snapshots. The initial build will show an empty comparison column because there are no previous snapshots.
  6. Finally, link your repo to Percy through "Project Settings" -> "Install an integration," selecting your organization and installing for all repositories.

Leveraging Percy's Power

Now, let's demonstrate Percy in a code review workflow:

  1. Create a branch (e.g., "changing-color").
  2. Modify a CSS file (e.g., change a color).
  3. Push the changes and create a pull request on GitHub.
  4. CircleCI will run Percy, highlighting the visual changes.
  5. Review the changes in Percy and approve them. This will mark the pull request as ready to merge.

Percy allows for efficient visual change review, preventing accidental UI regressions. This setup streamlines the UI testing process, saving significant time and effort.

The above is the detailed content of Testing for Visual Regressions with Percy. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1655
14
PHP Tutorial
1252
29
C# Tutorial
1226
24
Google Fonts   Variable Fonts Google Fonts Variable Fonts Apr 09, 2025 am 10:42 AM

I see Google Fonts rolled out a new design (Tweet). Compared to the last big redesign, this feels much more iterative. I can barely tell the difference

How to Create an Animated Countdown Timer With HTML, CSS and JavaScript How to Create an Animated Countdown Timer With HTML, CSS and JavaScript Apr 11, 2025 am 11:29 AM

Have you ever needed a countdown timer on a project? For something like that, it might be natural to reach for a plugin, but it’s actually a lot more

HTML Data Attributes Guide HTML Data Attributes Guide Apr 11, 2025 am 11:50 AM

Everything you ever wanted to know about data attributes in HTML, CSS, and JavaScript.

How to select a child element with the first class name item through CSS? How to select a child element with the first class name item through CSS? Apr 05, 2025 pm 11:24 PM

When the number of elements is not fixed, how to select the first child element of the specified class name through CSS. When processing HTML structure, you often encounter different elements...

Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Apr 05, 2025 pm 05:51 PM

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...

A Proof of Concept for Making Sass Faster A Proof of Concept for Making Sass Faster Apr 16, 2025 am 10:38 AM

At the start of a new project, Sass compilation happens in the blink of an eye. This feels great, especially when it’s paired with Browsersync, which reloads

How We Created a Static Site That Generates Tartan Patterns in SVG How We Created a Static Site That Generates Tartan Patterns in SVG Apr 09, 2025 am 11:29 AM

Tartan is a patterned cloth that’s typically associated with Scotland, particularly their fashionable kilts. On tartanify.com, we gathered over 5,000 tartan

See all articles