Percy Developer Hub

Welcome to the Percy Developer Hub. You'll find comprehensive guides and documentation to help you start working with Percy as quickly as possible, as well as support if you get stuck. Let's jump right in!

Selenium for Java


Covered in this doc

Installing Percy for Java with Selenium
Importing the Percy selenium library
Creating a new Percy object with a WebDriver instance as a parameter
Calling and configuring Percy snapshots

Maven CentralMaven Central


Add percy-java-selenium to your project dependencies. If you're using Maven:


If you're using a different build system, see for details for your specific system.

Install the Percy agent, which will upload snapshots on your behalf. It is available as a Node module, and you can install it using npm.

To install locally for your project:


If your project does not already have a package.json file in the root directory, run npm init and follow the prompts. Without a package.json present in the project, the next install step will fail.

$ npm install --save-dev @percy/agent

This will install the percy agent executable in a node_modules/ folder inside the current working directory. You can access the agent's executable at ./node_modules/.bin/percy.

In order to start creating snapshots from your Java Selenium scripts or tests, you'll need to import the io.percy.selenium.Percy function from the percy-java-selenium library. You will need to do this in each file from which you want to take snapshots:

import io.percy.selenium.Percy;

After you instantiate a Selenium WebDriver, create a new Percy instance:

Percy percy = new Percy(driver);

Use percy.snapshot(...) to generate a snapshot:

public void loadsHomePage() {

    // Take a Percy snapshot.
    percy.snapshot("Home Page");

Before you can successfully run Percy, the PERCY_TOKEN environment variable must be set:

# Windows 
$ set PERCY_TOKEN=<your token here>

# Windows PowerShell
$env:PERCY_TOKEN = "<your token here>"

# Unix 
$ export PERCY_TOKEN=<your token here>

Finally, wrap your program or test runner command in the percy exec command. This will start a Percy agent to receive snapshots from your tests and render screenshots for you to review in your Percy dashboard. For example, if you are using Maven to run your tests, your new test command becomes:

npx percy exec -- mvn test

Note the double dash, --, between percy exec and your test run command.

That's it! Now, whenever CI runs, a snapshot of the app in that state will be uploaded to Percy for visual regression testing!

For an example showing how to add Percy snapshots to an existing Selenium Java test suite, see


Percy constructor:

new Percy(driver)

driver is an object that implements the org.openqa.selenium.WebDriver interface.

Percy snapshot methods:

void snapshot(String name)
void snapshot(String name, @Nullable List<Integer> widths)
void snapshot(String name, @Nullable List<Integer> widths, @Nullable Integer minHeight)

snapshotName is a String that will be used as the snapshot name. It can be any string that makes sense to you to identify the page state. It should be unique and remain the same across builds.

widths is a List<Integer> representing the browser widths at which you want to take snapshots.

minHeight is an Integer specifying the minimum height of the resulting snapshot, in pixels. Defaults to 1024px.


WebDriver driver = new ChromeDriver();
Percy percy = new Percy(driver);
// ... use driver to navigate to the app and interact with it ..

percy.snapshot("Home page");
percy.snapshot("Home page responsive", Arrays.asList(768, 992, 1200));
percy.snapshot("Home page tall", Arrays.asList(768, 992, 1200), 2000);

Global Configuration

You can also configure Percy to use the same options over all snapshots. To see supported configuration including widths read our SDK configuration docs

Updated 6 months ago

What's next

Once you've set up Percy for Java, the next step is to add Percy to your CI service. That way, every time CI runs, Percy will automatically kick off visual tests as well.

CI integration overview

Selenium for Java

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.