Skip to main content

Espresso overview

This SDK allows you to work with Applitools Eyes using Espresso.

For information about installing and configuring this SDK, see Testing native Android apps using Espresso on the Applitools Tutorial site.

Espresso SDK allows you to test a mobile screen on a single device, using ClassicRunner, or test a mobile screen on multiple devices supported by Native Mobile Grid, using VisualGridRunner. Click here for a list of devices supported by Native Mobile Grid .

Getting started

To get started with this SDK, you need to set the following:

Entering the Applitools API key

To authenticate via the Applitools server and run tests, you need to set the environment variable APPLITOOLS_API_KEY to the API key provided from Applitools Eyes. For details how to retrieve your API key, see the Applitools documentation.

Entering the API Key on Linux or a Mac

export APPLITOOLS_API_KEY=<API_key>

Entering the API Key on Windows

set APPLITOOLS_API_KEY=<API_key>

Eyes server URL

If the Eyes server is not deployed in https://eyes.applitools.com, you need to set the Server URL in the environment variable APPLITOOLS_SERVER_URL before running tests.

The server URL of your Applitools Eyes dashboard is in the format https://<MY_COMPANY>.applitools.com

Entering the server URL on Linux or a Mac

export APPLITOOLS_SERVER_URL=<YOUR_SERVER_URL>

Entering the server URL on Windows

set APPLITOOLS_SERVER_URL=<YOUR_SERVER_URL>

A test in Applitools Eyes always starts with a eyes.open call and ends with eyes.close. The steps in the test are calls to eyes.check between eyes.open and eyes.close calls.

A test is structured as following:

eyes.open
[step 1]
[step 2]
...
eyes.close

Runner

This SDK uses the following Runner classes:

  • ClassicRunner – Used when running multiple Eyes sessions.
  • VisualGridRunner – Used to manage sessions when working with the Native Mobile Grid.

ClassicRunner class

An object of this class is used to manage multiple Eyes sessions when working without the Native Mobile Grid

For a details of arguments, see ClassicRunner class.

Constructor

To define the class:

EyesRunner runner = new ClassicRunner();

GetAllTestResults

This command returns an object with the Eyes test results from a given test or test file. This command should be called after all Eyes tests have been completed.

TestResultsSummary allTestResults = runner.getAllTestResults();
System.out.println(allTestResults);

dontCloseBatches

If true, the batch is not closed when GetAllTestResults is called.

runner.setDontCloseBatches(true)

VisualGrid runner

An object of this class is used to manage multiple Eyes sessions when working with the Native Mobile Grid. The Native Mobile Grid allows you to create screenshot from supported mobile devices and compare the output in Applitools Eyes.

Constructor

To define the class:

EyesRunner runner = new VisualGridRunner(new RunnerOptions().testConcurrency(5));

GetAllTestResults

This command returns an object with the results from a test or test file. This command should be called after all Eyes tests have been completed.

Example

TestResultsSummary allTestResults = runner.getAllTestResults();
Log.i(TAG, allTestResults);

Eyes class

Eyes Class enables visual testing with Applitools Eyes.

Constructor

To define the class:

Eyes eyes = new Eyes(runner);

eyes.open

This method creates an Eyes test. This will start a session with the Applitools server.

eyes.open("app name", "test name");

Where:

  • "app name" – The application name, this may be any string. You can set the application name for all tests using Configuration.setAppName, in which case you do not need to set the app name, use use eyes.open("test name");.
  • "test name" – The name of the test. This name must be unique within the scope of the application name. It may be any string.

eyes.check

This command generates a screenshot of the application and adds it to the Eyes test.

eyes.check(Target.window());

For details of eyes.check arguments, see CheckSettings class.

eyes.close

This command closes the Eyes test and checks that all screenshots are valid. It is important to call this command at the end of each test, symmetrically to eyes.open.

eyes.close receives no arguments.

eyes.closeAsync();

Sample test

To help you get started, the following samples check the initial screen in your application:

Classic (when Native Mobile Grid is not Used)

ExampleInstrumentedTest.java

With Native Mobile Gid

Native Mobile Grid Test available soon

Other Significant classes

When working with this SDK, you should be familiar with the following classes:

  • BatchInfo class – Call the Configuration.setBatch method with an object of this class to configure the batch for one or more test.

  • Configuration class – Used to create a configuration object that is used to configure an Eyes object by passing it to the Eyes.setConfiguration method.