Android APIs
public final class

Espresso

extends Object
java.lang.Object
   ↳ android.support.test.espresso.Espresso

Class Overview

Entry point to the Espresso framework. Test authors can initiate testing by using one of the on* methods (e.g. onView) or perform top-level user actions (e.g. pressBack).

Summary

Public Methods
static void closeSoftKeyboard()
Closes soft keyboard if open.
static List<IdlingResource> getIdlingResources()
Returns a list of all currently registered IdlingResources.
static DataInteraction onData(Matcher<? extends Object> dataMatcher)
Creates an DataInteraction for a data object displayed by the application.
static ViewInteraction onView(Matcher<View> viewMatcher)
Creates a ViewInteraction for a given view.
static void openActionBarOverflowOrOptionsMenu(Context context)
Opens the overflow menu displayed within an ActionBar.
static void openContextualActionModeOverflowMenu()
Opens the overflow menu displayed in the contextual options of an ActionMode.
static void pressBack()
Press on the back button.
static boolean registerIdlingResources(IdlingResource... resources)
Registers one or more IdlingResources with the framework.
static void registerLooperAsIdlingResource(Looper looper, boolean considerWaitIdle)
Registers a Looper for idle checking with the framework.
static void registerLooperAsIdlingResource(Looper looper)
Registers a Looper for idle checking with the framework.
static void setFailureHandler(FailureHandler failureHandler)
Changes the default FailureHandler to the given one.
static boolean unregisterIdlingResources(IdlingResource... resources)
Unregisters one or more IdlingResources.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static void closeSoftKeyboard ()

Closes soft keyboard if open.

public static List<IdlingResource> getIdlingResources ()

Returns a list of all currently registered IdlingResources.

public static DataInteraction onData (Matcher<? extends Object> dataMatcher)

Creates an DataInteraction for a data object displayed by the application. Use this method to load (into the view hierarchy) items from AdapterView widgets (e.g. ListView).

Parameters
dataMatcher a matcher used to find the data object.

public static ViewInteraction onView (Matcher<View> viewMatcher)

Creates a ViewInteraction for a given view. Note: the view has to be part of the view hierarchy. This may not be the case if it is rendered as part of an AdapterView (e.g. ListView). If this is the case, use Espresso.onData to load the view first.

Parameters
viewMatcher used to select the view.

public static void openActionBarOverflowOrOptionsMenu (Context context)

Opens the overflow menu displayed within an ActionBar.

This works with both native and SherlockActionBar ActionBars.

Note the significant differences of UX between ActionMode and ActionBars with respect to overflows. If a hardware menu key is present, the overflow icon is never displayed in ActionBars and can only be interacted with via menu key presses.

public static void openContextualActionModeOverflowMenu ()

Opens the overflow menu displayed in the contextual options of an ActionMode.

This works with both native and SherlockActionBar action modes.

Note the significant difference in UX between ActionMode and ActionBar overflows - ActionMode will always present an overflow icon and that icon only responds to clicks. The menu button (if present) has no impact on it.

public static void pressBack ()

Press on the back button.

Throws
PerformException if currently displayed activity is root activity, since pressing back button would result in application closing.

public static boolean registerIdlingResources (IdlingResource... resources)

Registers one or more IdlingResources with the framework. It is expected, although not strictly required, that this method will be called at test setup time prior to any interaction with the application under test. When registering more than one resource, ensure that each has a unique name. If any of the given resources is already registered, a warning is logged.

Returns
  • true if all resources were successfully registered

public static void registerLooperAsIdlingResource (Looper looper, boolean considerWaitIdle)

Registers a Looper for idle checking with the framework. This is intended for use with non-UI thread loopers.

This method allows the caller to consider Thread.State.WAIT to be 'idle'.

This is useful in the case where a looper is sending a message to the UI thread synchronously through a wait/notify mechanism.

Throws
IllegalArgumentException if looper is the main looper.

public static void registerLooperAsIdlingResource (Looper looper)

Registers a Looper for idle checking with the framework. This is intended for use with non-UI thread loopers.

Throws
IllegalArgumentException if looper is the main looper.

public static void setFailureHandler (FailureHandler failureHandler)

Changes the default FailureHandler to the given one.

public static boolean unregisterIdlingResources (IdlingResource... resources)

Unregisters one or more IdlingResources. If any of the given resources are not already registered, a warning is logged.

Returns
  • true if all resources were successfully unregistered