### [percy-java-selenium on GitHub <i class="fa fa-github" aria-hidden="true"></i>](🔗)
Visual regression testing for [Selenium](🔗) Java tests with Percy.
Make sure you have completed [Setup](🔗) of your CI service first. You can also test Percy in your [local development](🔗) environment.
percy-java-selenium` to your project dependencies. If you're using Maven:
If you're using a different build system, see https://search.maven.org/artifact/io.percy/percy-java-selenium for details for your specific system.
Make sure to use at least version 0.0.3 of the SDK. (Previous versions were compiled with Java 11.)
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.
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 `
# Quick Setup
These are the minimal steps required to add visual testing to your existing Selenium code:
Import the Percy selenium library into your file: `
Create a new Percy object, with a WebDriver instance as a parameter: `
Percy percy = new Percy(webDriver);`
percy.snapshot(SNAPSHOT_NAME)` wherever you want to save a snapshot.
Wrap your run command in `
percy exec --`, e.g. `
./node_modules/.bin/percy exec -- mvn test`.
Next, we will go through each of these steps in detail.
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:
After you instantiate a Selenium WebDriver, create a new Percy instance:
percy.snapshot(...)` to generate a snapshot:
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 upload them to your Percy dashboard. For example, if you are using Maven to run your tests, your new test command becomes:
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 [https://github.com/percy/example-percy-java-selenium/pull/3](🔗).
driver` is an object that implements the `
Percy snapshot methods:
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.
# Global Configuration
You can also configure Percy to use the same options over all snapshots. To see supported configuration including widths read our [Configuration doc](🔗).
Fork it ( https://github.com/percy/percy-java-selenium/fork )
Create your feature branch (`
git checkout -b my-new-feature`)
Commit your changes (`
git commit -am 'Add some feature'`)
Push to the branch (`
git push origin my-new-feature`)
Create a new pull request
[Throw a ★ on it!](🔗) 😄