Skip to main content
🚀 Become an AI-ready QA professional: Join 5k+ QAs at global summit shaping the future of testing! Register Now!
No Result Found
Get help or connect with the developer community Join Discord Community -> Join Discord Community ->

Run a sample Percy build with Selenium and Java

Get hands-on experience running Percy with Selenium and Java 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:

Prerequisites

Before you start, ensure that you have the following installed:

Clone the sample application
Clone the example-percy-java-selenium application, change the directory, and compile the sample application by running these commands:

Copy icon Copy

You can explore the sample application by opening the src/main/resources/index.html file.

Create a Percy project
To create a project, follow these steps:

  1. Sign in to Percy.
  2. In Percy, create a project of the type, Web.
  3. Name the project. After the project is created, Percy generates a token.
  4. Note down the token. You have to use it to set your environment variable in the next step.

For details on creating a project, see Create a Percy project.

Set the project token as an environment variable
Run the given command to set PERCY_TOKEN as an environment variable:

Copy icon Copy
Copy icon Copy
Copy icon Copy

To learn about environment variables in Percy, see Percy environment variables.

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 App.java file in which the method is called. The goal is to have a visual build with which to compare a later build.

Copy icon Copy

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.

Screenshot of the sample application on the Percy dashboard

Modify the sample application

Edit the src/main/resources/index.html file to introduce some visual changes. In our example, we are adding inline CSS to bold the Clear Completed button on line 32 of the file.

Copy icon Copy

Commit your changes

Commit the changes you made to the sample application by running the following command:

Copy icon Copy

Generate the second build
Run the test script again.

Copy icon Copy

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

  1. Open your project dashboard to view your builds.
  2. 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.

Percy highlights what’s changed visually in the application. Use the options on the screen to review the changes on different browsers and widths.

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.

Follow these steps to clone the sample web application, run a build, and view the results of the visual comparison:

Prerequisites

Before you start, ensure that you have:

  • Installed Git and Node 14+ with npm
  • The following, if your test scripts are in Java:
    • TestNG v6.8+
    • Java v8+
    • Selenium v2.5+ (W3C/JSON Wire)
    • Maven (installed, environment variables set, and bin added to the system path)

Run your Percy build on Automate

Clone the sample application
Clone our sample repository and install the dependencies by running the following commands:

Copy icon Copy

Set BrowserStack credentials
Get your BrowserStack credentials and update the sample script.

  1. Sign up with BrowserStack for a free trial or purchase a plan.
  2. Get your username and access key from the BrowserStack profile page.
  3. Use the userName and accessKey variables to set BrowserStack environment variables to authenticate your tests.
Copy icon Copy
Copy icon Copy
Copy icon Copy

Alternatively, update USER_NAME and ACCESS_KEY in the test file.

Run the first build
Run your first Percy build on Automate by using the following command:

Copy icon Copy

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:

  • Run the framework’s after-test file using the run command from Step 4. Use the file PercyTest.java. You can skip Step 6 and go directly to the Automate and Percy dashboards to view your functional and visual builds

or

  • Search for the below line in the test file and replace the @id=”1” to @id=”3”:
Copy icon Copy

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.

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle