Skip to main content

Testing native Android apps using Espresso

✅ Prerequisites

  1. Create a free Applitools account and get your Applitools API KEY

  2. Install git from​


    Installing git is optional. You need this mainly to clone the demo project from the Github repository. Instead of installing git, you can simply download the Zip file from the repo. Further, If you are using Mac OSX, you already have git.

  3. Android Studio

🚀 - Run the existing demo app

  1. Get the code:

    • Option 1: git clone
    • Option 2: Download it as a Zip file and unzip it.
  2. Import the project into Android Studio

  3. Run the test by clicking the Run Button to the left of the simpleTest() method. ::: tip This method is located in the file. Be sure to set your API key in the line that says eyes.setApiKey("YOUR_API_KEY"); :::

🤓 - Add Applitools to an existing project

Add the Maven repository to your build.gradle file

buildscript {
// ...
repositories {
// ...
maven {
url ''

Include the SDK in your build.gradle file

androidTestImplementation 'com.applitools:eyes-android-espresso:latest.release'

Example Espresso Instrumented Test


import static androidx.test.espresso.Espresso.onView;
import static;
import static androidx.test.espresso.matcher.ViewMatchers.withId;

import android.util.Log;
import android.view.View;

import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.rule.ActivityTestRule;


import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

public class DocumentationExampleTest {

private static final String TAG = "DocumentationExampleTest";

public ActivityTestRule<MainActivity> mMainActivityRule = new ActivityTestRule(MainActivity.class, false, false);

public ActivityTestRule<DialogActivity> mDialogActivityRule = new ActivityTestRule(DialogActivity.class, false, false);

public ActivityTestRule<GoogleMapsActivity> mGoogleMapActivityRule = new ActivityTestRule(GoogleMapsActivity.class, false, false);

private static final String eyesServerUrl = "";
private static final String appName = "EKB Example : classic app";
private static final String batchName = "EKB Example : classic";
private static final String apiKey = "YOUR_API_KEY";
private static final String testName = "Hello World test";
private static EyesRunner runner = null;
private static Configuration suiteConfig;
private Eyes eyes;

public static void beforeTestSuite() {
runner = new ClassicRunner();
suiteConfig = new Configuration();
.setBatch(new BatchInfo(batchName));

public void beforeEachTest() {
eyes = new Eyes(runner);
Uncomment the call to 'eyes.setComponentsProvider' if you use AndroidX components such as
NestedScrollView, RecyclerView and ViewPager2
//eyes.setComponentsProvider(new AndroidXComponentsProvider());

public void testStartScreen() {

eyes.check("Click me button",Target.region(ViewMatchers.withId(;

View helloLabel = mMainActivityRule.getActivity().findViewById(;
eyes.check("HelloWorld label", Target.region(helloLabel));

Region region = new Region(200, 300, 0, 0);

eyes.check("Before button click", Target.window());

eyes.check("After button click", Target.window());

public void testDialog() {
mDialogActivityRule.launchActivity(null);"Dialog test");

//TBD - can we add examples with a popup or dialog and then show the 3 possibilities of
eyes.check("main viewport only",Target.window());
eyes.check("dialog only",Target.window().dialog());
eyes.check("Both main viewport and dialog",Target.window().includeAllLayers());

public void testGoogleMap() {
mGoogleMapActivityRule.launchActivity(null);"GoogleMaps test");

eyes.check("A googleMap", Target.googleMap().id(;
// eyes.check("Not a SupportMapFragment", Target.googleMap().id(;

public void afterEachTest() {
try {
} finally {

public static void afterTestSuite() {
TestResultsSummary allTestResults = runner.getAllTestResults(false);
for (TestResultContainer result : allTestResults) {

private static void handleTestResults(TestResultContainer summary) {
Throwable ex = summary.getException();
if (ex != null) {
Log.e(TAG, "System error occurred while checking target.");
TestResults result = summary.getTestResults();
if (result == null) {
Log.e(TAG, "No test results information available.");
} else {
Log.d(TAG, String.format("URL = %s, AppName = %s, testName = %s, matched = %d, mismatched = %d, missing = %d, aborted = %s",
(result.isAborted() ? "aborted" : "no")));
Having Trouble?

Don't suffer in silence! Let us help you. Please reach out to us to get your project working.

Taking the next steps with Applitools

Congratulations on completing this quickstart! There's still so much to learn about visual testing with Applitools, but you're off to a great start.

Resources for next steps:

  1. 🤖 Learning how visual testing works
  2. ↔️ Setting match levels for visual checkpoints
  3. 💥 Troubleshooting common issues
  4. 🐞 Reporting bugs
  5. 🗺 Detailed overview of visual testing with Applitools

You can also: