Screenshots Java Tutorial

Getting Started with Applitools

Want to learn more about the Applitools platform and how it works? First get started with one of the following:

Running Tests with Applitools

Prerequisites
  1. A free Applitools account and Applitools API KEY

Tip: Unsure how to set up your API key?

Learn how to get started at Setting Up

  1. Java v8 or higher https://www.java.com/en/download/help/download_options.xml

  2. Maven https://maven.apache.org/

Tip: Not sure how to install?

Here are some resources:

Make sure it's in your PATH!

To test that it's working:

  • Make sure to restart the Terminal or Command line prompt to load the new environment variables.
  • Run mvn -v

You should see the version info for Maven.

TIP

  1. It's better if you add it permanently to the environment so when you open a new Terminal the values will persist. Otherwise, you may have to redo it for everytime you open the Terminal. This means you should put it in the ~/.bash_profile file (Mac) or in System variables in Windows. For more, see the Steps for adding Chromedriver to the PATH below.
  2. The Maven executable is inside /bin folder of the extracted Maven directory. So you must include /bin. It should look something like: /Users/raja/apps/apache-maven-3.5.4/bin

Running the Example Project

  1. Clone or download the repository and navigate to that folder
git clone https://github.com/applitools/tutorial-images-java.git
cd tutorial-images-java
1
2

Note: you can alternatively download the project as a Zip file and extract it

  1. Run the example test
APPLITOOLS_API_KEY="[Your API Key]" mvn clean -Dtest=DemoTest test
1

Adding Applitools Eyes to an Existing Project

  1. Create a Maven project and add the following properties and dependencies to the pom.xml
  <dependencies>
    <!-- This is the Applitools Images Java SDK -->
    <dependency>
     <groupId>com.applitools</groupId>
     <artifactId>eyes-images-java3</artifactId>
     <version>RELEASE</version>
    </dependency>
  </dependencies>
1
2
3
4
5
6
7
8
  1. Create a class with name DemoTest.java and add the following code
package com.applitools.app;

import com.applitools.eyes.images.Eyes;
import com.applitools.eyes.images.Target;
import com.applitools.eyes.RectangleSize;

import org.junit.jupiter.api.Test;
import java.net.URL;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.nio.file.Paths;

public class DemoTest {
    @Test
    public void test() {
        
        Eyes eyes = new Eyes();

        // // Define the OS and hosting application to identify the baseline.
        eyes.setHostOS("Windows 10");
        eyes.setHostApp("My maxthon browser");

        try {
            // Start the test with a viewport size of 800x600.
            eyes.open("Demo App - Images Java", "Smoke Test - Images Java", new RectangleSize(800, 600));

            // Load page image and validate.
            BufferedImage img = ImageIO.read(new URL("https://i.ibb.co/bJgzfb3/applitools.png"));

            // // Visual validation.
            eyes.check("Image buffer", Target.image(img));

            // End visual UI testing.
            eyes.close();
        } catch(IOException ex){
            System.out.println(ex);
        } finally {
            // If the test was aborted before eyes.close was called, ends the test as aborted.
            eyes.abortIfNotClosed();
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

Resources




Terms & Conditions Privacy Policy GDPR© 2021 Applitools. All rights reserved.

Last Updated: 6/24/2021, 10:09:59 AM