search
HomeWeb Front-endCSS TutorialTesting for Visual Regressions with Percy

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

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
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
What is CSS Grid?What is CSS Grid?Apr 30, 2025 pm 03:21 PM

CSS Grid is a powerful tool for creating complex, responsive web layouts. It simplifies design, improves accessibility, and offers more control than older methods.

What is CSS flexbox?What is CSS flexbox?Apr 30, 2025 pm 03:20 PM

Article discusses CSS Flexbox, a layout method for efficient alignment and distribution of space in responsive designs. It explains Flexbox usage, compares it with CSS Grid, and details browser support.

How can we make our website responsive using CSS?How can we make our website responsive using CSS?Apr 30, 2025 pm 03:19 PM

The article discusses techniques for creating responsive websites using CSS, including viewport meta tags, flexible grids, fluid media, media queries, and relative units. It also covers using CSS Grid and Flexbox together and recommends CSS framework

What does the CSS box-sizing property do?What does the CSS box-sizing property do?Apr 30, 2025 pm 03:18 PM

The article discusses the CSS box-sizing property, which controls how element dimensions are calculated. It explains values like content-box, border-box, and padding-box, and their impact on layout design and form alignment.

How can we animate using CSS?How can we animate using CSS?Apr 30, 2025 pm 03:17 PM

Article discusses creating animations using CSS, key properties, and combining with JavaScript. Main issue is browser compatibility.

Can we add 3D transformations to our project using CSS?Can we add 3D transformations to our project using CSS?Apr 30, 2025 pm 03:16 PM

Article discusses using CSS for 3D transformations, key properties, browser compatibility, and performance considerations for web projects.(Character count: 159)

How can we add gradients in CSS?How can we add gradients in CSS?Apr 30, 2025 pm 03:15 PM

The article discusses using CSS gradients (linear, radial, repeating) to enhance website visuals, adding depth, focus, and modern aesthetics.

What are pseudo-elements in CSS?What are pseudo-elements in CSS?Apr 30, 2025 pm 03:14 PM

Article discusses pseudo-elements in CSS, their use in enhancing HTML styling, and differences from pseudo-classes. Provides practical examples.

See all articles

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

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool