Get hands-on experience on running Percy with Playwright using our sample repository
With Percy, you can automate the visual testing of web applications, ensuring visual consistency across different releases and preventing visual regressions. This page demonstrates how to use Percy Standalone and Percy with Automate to run visual tests on a sample web application.
Follow these steps to clone the sample web application, run a build, and view the results of the visual comparison:
Clone the sample application
Clone the example-percy-playwright application, change the directory, and compile the sample application by running these commands:
Generate the first build
In this step, we run the sample test script to take a few snapshots using the percy.snapshot method. The sample application contains an file in which the method is called. The goal is to have a visual build with which to compare a later build.
$ cd web
$ npx percy exec --verbose -- dotnet test --filter "Category=web-percy-test"
On completion, you see logs from Percy confirming that the snapshots were successfully uploaded and a direct URL to the dashboard. There are no visual comparisons yet.
$ npx percy exec --verbose -- dotnet test --filter "Category=web-percy-after-test"
Commit your changes
Commit the changes that you made to the sample application.
Generate the second build
Run the test script again.
Follow Step 4 to generate your second build.
This takes new screenshots of our modified application, uploads them to Percy, and compares them with the previous screenshots to show visual differences.
View results
Open your project dashboard to view your builds.
Open the second build to view the visual differences in comparison to the first build.
On the third pane, you see the screenshots from the first build on the left, and from the second, on the right.
You’ve successfully run the sample Percy build.
As you’ve seen, Percy helps you capture visual differences in your application that go undetected with functional testing alone.
This was just a sneak peek. Percy can do a lot more. To make the best out of it, integrate Percy with your test suite. To know more check out the related topics.
$ cd automate
$ npx percy exec --verbose -- dotnet test --filter "Category=automate-percy-test"
Your first Percy on Automate build is created. As this is the first build, no comparisons are available yet. You must approve the first build to have a base build for future comparisons.
The Percy screenshot command is used to capture screenshots in your Automate session. Refer to the tests mentioned in the git repository.
Modify the sample application
To modify the sample application, perform one of the following:
Directly run the after_test test file provided in the project using the run command in Step 4. In this case, you can skip Step 6 and directly visit the Automate and the Percy dashboards to see your functional and visual builds.
Search for the below line in the test file and replace the @id=”1” to @id=”3”:
Commit changes
Commit the changes that you made to the sample application.
Run the second build
Follow Step 4 to generate your second build.
After the script execution is finished, the current build is compared to the previously approved build.
View results
Visit the Automate and the Percy dashboards to see your functional and visual builds.
Congratulations!
You’ve successfully run the sample Percy build. As you’ve seen, Percy helps you capture visual differences in your application that go undetected with functional testing alone.
This was just a sneak peek. Percy can do a lot more. To make the best out of it, integrate Percy with your test suite. To know more check out the related topics.