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.
- Clone the Netlify-deployed repo (e.g.,
git clone https://github.com/PaulRyanStitcherAds/gatsby-starter-netlify-cms.git
). - Sign up for CircleCI using your GitHub account.
- Add your project in CircleCI, selecting Linux and Ruby (for percy-cli).
- 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
- Create a Percy account using GitHub.
- Create a new organization and project in Percy.
- Obtain your Percy token from "Project Settings."
- Add the token as an environment variable in CircleCI's "Build Settings."
- 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.
- 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:
- Create a branch (e.g., "changing-color").
- Modify a CSS file (e.g., change a color).
- Push the changes and create a pull request on GitHub.
- CircleCI will run Percy, highlighting the visual changes.
- 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!

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

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.

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

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.

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

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

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

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


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

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
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
