Page tree
Skip to end of metadata
Go to start of metadata

by Uzi Eilon

Execute Espresso Tests on Perfecto Devices

Espresso is an open source framework provided by Google which allows to execute UI tests on Android apps. 
It is an instrumentation-based API and works with the AndroidJUnitRunner test runner.

After instrument the app the tool provide easy way to access the objects and execute actions and validations.

Setup the Espresso

In order to add Espresso test to your project you should :
1. Install it , by adding the lib to the gradle file:

androidTestCompile ''
androidTestCompile ''
2. Instrument the app ,by adding this line to your gradle file:
testInstrumentationRunner ""

Building the app with the following configuration will open the Espresso API and you can start write your tests.

How to write Espresso tests?

Espresso commands are sync with the UI and wait for the elements.
The command build from the following steps:

      • onView(object identifier) - wait for the element to appear in the UI.
      • perform - execute actions in the element
      • check - validation


Example - The following test open the Calc app enter percentage values and validate the results:

onView(withText("Perfecto Calc:")).check(matches(isDisplayed()));
onView(withId("10.0")))   onView(withId("20"),closeSoftKeyboard());

Calc app
Device in perfecto system while the test is running

Why Perfecto?

  • Perfecto cloud allows you to execute your existing Espresso tests on any real devices with any Android version.
  • Perfecto system generates rich report include the test video so you can get more details on your test.
  • Visual validation - Espresso tests work on the objects but can't validate the if the objects display properly
    Perfecto allows you to add visual validation to avoid the following issue:

Same app - rotate device
only visual validation can find the bug above

How to start ?

In order to execute the Espresso test from command line you should use Espresso Executecommand :

adb shell am instrument -w <apppackage>/

New command named "Espresso Execute" added.

      1. Application Package Name
      2. Timeout


The command executes the test via shell command on the device and shows the results in Perfecto reports.

Espresso execution

This video shows how to execute the Espresso command on Perfecto device and how the results present in the report