Skip to main content

Integrate Visual AI Checkpoints Into An Existing Project

This guide will show you how to add Visual AI Checkpoints to your existing Selenium Java project.

Install Dependencies

Install the Eyes SDK

Add the following to your pom.xml file:

<dependency>
<groupId>com.applitools</groupId>
<artifactId>eyes-selenium-java5</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
Latest Version

Checkout the official Maven repository page for the Selenium Java SDK to get the latest version.

Setting Up Your Environment

Before running the visual test, set up your API key as an environment variable named APPLITOOLS_API_KEY. You may set it through your IDE (if applicable), or you may set it from the command line like this:

export APPLITOOLS_API_KEY=<your-api-key>

Modify Your Tests

To run a Visual AI Checkpoint, there are 3 main steps:

  1. Call eyes.open()
  2. Call eyes.check() to perform Visual AI assertions
  3. Call eyes.closeAsync()

Calling eyes.open()

The eyes.open() command initializes a session with the Applitools server, allows you to configure the Eyes object and marks the beginning of a Visual AI Test.

This function must be called before any calls to eyes.check(). Therefore, it is recommended to place it in the beforeEach hook or equivalent for your test suite:

eyes.open(driver,"ACME Bank", "Log into a bank account", new RectangleSize(1200, 600));

Calling eyes.check()

The eyes.check() command takes a Visual AI assertion of the current status of the page that you're testing. This method should be called within your actual test:

// Capture the full web page
eyes.check(Target.window().fully().withName("Main page"));

Calling eyes.closeAsync()

The eyes.closeAsync() command is the opposite of eyes.open() and marks the end of your Visual AI Test. This method should be called once per call to eyes.open(). So, if you're calling eyes.open() in the beforeEach hook, then call this method in the AfterEach hook or equivalent:

// End Applitools Visual AI Test
eyes.closeAsync();

Full Example

Below is an example of a test case that uses Visual AI Assertions:


Next Steps