# Espresso

Summary:[Methods](https://developer.android.com/reference/android/support/test/espresso/Espresso#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/test/espresso/Espresso#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/test/espresso/Espresso#)  

# Espresso

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public

final

class
Espresso
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object.html)`


``


`

|---|----------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) ||
| ↳ | android.support.test.espresso.Espresso |

<br />

*** ** * ** ***

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](https://developer.android.com/reference/android/support/test/espresso/Espresso#closeSoftKeyboard())`() ` Closes soft keyboard if open.                                                                                                                                                                                                                                                                                                                                                                              |
| ` static `[List](https://developer.android.com/reference/java/util/List.html)`<`[IdlingResource](https://developer.android.com/reference/android/support/test/espresso/IdlingResource)`>` | ` `[getIdlingResources](https://developer.android.com/reference/android/support/test/espresso/Espresso#getIdlingResources())`() ` *This method is deprecated. use[getResources()](https://developer.android.com/reference/android/support/test/espresso/IdlingRegistry#getResources())instead.*                                                                                                                                                                                                                                            |
| ` static `[DataInteraction](https://developer.android.com/reference/android/support/test/espresso/DataInteraction)                                                                        | ` `[onData](https://developer.android.com/reference/android/support/test/espresso/Espresso#onData(org.hamcrest.Matcher<? extends java.lang.Object>))`(Matcher<? extends `[Object](https://developer.android.com/reference/java/lang/Object.html)`> dataMatcher) ` Creates an[DataInteraction](https://developer.android.com/reference/android/support/test/espresso/DataInteraction)for a data object displayed by the application.                                                                                                        |
| ` static void`                                                                                                                                                                            | ` `[onIdle](https://developer.android.com/reference/android/support/test/espresso/Espresso#onIdle())`() ` Loops the main thread until the app goes idle.                                                                                                                                                                                                                                                                                                                                                                                   |
| ` static <T> T`                                                                                                                                                                           | ` `[onIdle](https://developer.android.com/reference/android/support/test/espresso/Espresso#onIdle(java.util.concurrent.Callable<T>))`(`[Callable](https://developer.android.com/reference/java/util/concurrent/Callable.html)`<T> action) ` Loops the main thread until the app goes idle.                                                                                                                                                                                                                                                 |
| ` static `[ViewInteraction](https://developer.android.com/reference/android/support/test/espresso/ViewInteraction)                                                                        | ` `[onView](https://developer.android.com/reference/android/support/test/espresso/Espresso#onView(org.hamcrest.Matcher<android.view.View>))`(Matcher<`[View](https://developer.android.com/reference/android/view/View.html)`> viewMatcher) ` Creates a[ViewInteraction](https://developer.android.com/reference/android/support/test/espresso/ViewInteraction)for a given view.                                                                                                                                                           |
| ` static void`                                                                                                                                                                            | ` `[openActionBarOverflowOrOptionsMenu](https://developer.android.com/reference/android/support/test/espresso/Espresso#openActionBarOverflowOrOptionsMenu(android.content.Context))`(`[Context](https://developer.android.com/reference/android/content/Context.html)` context) ` Opens the overflow menu displayed within an ActionBar.                                                                                                                                                                                                   |
| ` static void`                                                                                                                                                                            | ` `[openContextualActionModeOverflowMenu](https://developer.android.com/reference/android/support/test/espresso/Espresso#openContextualActionModeOverflowMenu())`() ` Opens the overflow menu displayed in the contextual options of an ActionMode.                                                                                                                                                                                                                                                                                        |
| ` static void`                                                                                                                                                                            | ` `[pressBack](https://developer.android.com/reference/android/support/test/espresso/Espresso#pressBack())`() ` Press on the back button.                                                                                                                                                                                                                                                                                                                                                                                                  |
| ` static void`                                                                                                                                                                            | ` `[pressBackUnconditionally](https://developer.android.com/reference/android/support/test/espresso/Espresso#pressBackUnconditionally())`() ` Similar to[pressBack()](https://developer.android.com/reference/android/support/test/espresso/Espresso#pressBack())but will**not**throw an exception when Espresso navigates outside the application or process under test.                                                                                                                                                                  |
| ` static boolean`                                                                                                                                                                         | ` `[registerIdlingResources](https://developer.android.com/reference/android/support/test/espresso/Espresso#registerIdlingResources(android.support.test.espresso.IdlingResource...))`(`[IdlingResource...](https://developer.android.com/reference/android/support/test/espresso/IdlingResource)` resources) ` *This method is deprecated. use[register(IdlingResource)](https://developer.android.com/reference/android/support/test/espresso/IdlingRegistry#register(android.support.test.espresso.IdlingResource...))instead.*         |
| ` static void`                                                                                                                                                                            | ` `[registerLooperAsIdlingResource](https://developer.android.com/reference/android/support/test/espresso/Espresso#registerLooperAsIdlingResource(android.os.Looper))`(`[Looper](https://developer.android.com/reference/android/os/Looper.html)` looper) ` *This method is deprecated. use[registerLooperAsIdlingResource(Looper)](https://developer.android.com/reference/android/support/test/espresso/IdlingRegistry#registerLooperAsIdlingResource(android.os.Looper))instead.*                                                       |
| ` static void`                                                                                                                                                                            | ` `[registerLooperAsIdlingResource](https://developer.android.com/reference/android/support/test/espresso/Espresso#registerLooperAsIdlingResource(android.os.Looper, boolean))`(`[Looper](https://developer.android.com/reference/android/os/Looper.html)` looper, boolean considerWaitIdle) ` *This method is deprecated. use[registerLooperAsIdlingResource(Looper)](https://developer.android.com/reference/android/support/test/espresso/IdlingRegistry#registerLooperAsIdlingResource(android.os.Looper))instead.*                    |
| ` static void`                                                                                                                                                                            | ` `[setFailureHandler](https://developer.android.com/reference/android/support/test/espresso/Espresso#setFailureHandler(android.support.test.espresso.FailureHandler))`(`[FailureHandler](https://developer.android.com/reference/android/support/test/espresso/FailureHandler)` failureHandler) ` Changes the default[FailureHandler](https://developer.android.com/reference/android/support/test/espresso/FailureHandler)to the given one.                                                                                              |
| ` static boolean`                                                                                                                                                                         | ` `[unregisterIdlingResources](https://developer.android.com/reference/android/support/test/espresso/Espresso#unregisterIdlingResources(android.support.test.espresso.IdlingResource...))`(`[IdlingResource...](https://developer.android.com/reference/android/support/test/espresso/IdlingResource)` resources) ` *This method is deprecated. use[unregister(IdlingResource)](https://developer.android.com/reference/android/support/test/espresso/IdlingRegistry#unregister(android.support.test.espresso.IdlingResource...))instead.* |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/test/espresso/Espresso#)From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object.html)` ` |-------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object.html)          | ` clone() `                                                                                | | ` boolean`                                                                          | ` equals(`[Object](https://developer.android.com/reference/java/lang/Object.html)` arg0) ` | | ` void`                                                                             | ` finalize() `                                                                             | | ` final `[Class](https://developer.android.com/reference/java/lang/Class.html)`<?>` | ` getClass() `                                                                             | | ` int`                                                                              | ` hashCode() `                                                                             | | ` final void`                                                                       | ` notify() `                                                                               | | ` final void`                                                                       | ` notifyAll() `                                                                            | | ` `[String](https://developer.android.com/reference/java/lang/String.html)          | ` toString() `                                                                             | | ` final void`                                                                       | ` wait(long arg0, int arg1) `                                                              | | ` final void`                                                                       | ` wait(long arg0) `                                                                        | | ` final void`                                                                       | ` wait() `                                                                                 | ||

## Public methods

### closeSoftKeyboard

```
void closeSoftKeyboard ()
```

Closes soft keyboard if open.

<br />

### getIdlingResources

```
List<IdlingResource> getIdlingResources ()
```

<br />

**This method is deprecated.**   
use[getResources()](https://developer.android.com/reference/android/support/test/espresso/IdlingRegistry#getResources())instead.

Returns a list of all currently registered[IdlingResource](https://developer.android.com/reference/android/support/test/espresso/IdlingResource)s.

<br />

|                                                                                         Returns                                                                                         ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------|
| [List](https://developer.android.com/reference/java/util/List.html)`<`[IdlingResource](https://developer.android.com/reference/android/support/test/espresso/IdlingResource)`>` | <br /> |

### onData

```
DataInteraction onData (Matcher<? extends Object> dataMatcher)
```

Creates an[DataInteraction](https://developer.android.com/reference/android/support/test/espresso/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).

This method builds a DataInteraction object - it does not interact with the application under test at all. It is expected that the caller use the ViewInteraction object to perform an action or assertion.

<br />

|                                Parameters                                ||
|---------------|-----------------------------------------------------------|
| `dataMatcher` | `Matcher`: a matcher used to find the data object. <br /> |

|                                                                                   Returns                                                                                    ||
|----------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------|
| [DataInteraction](https://developer.android.com/reference/android/support/test/espresso/DataInteraction) | a DataInteraction that will perform an action or assertion. <br /> |

### onIdle

```
void onIdle ()
```

Loops the main thread until the app goes idle.

Only call this method for tests that do not interact with any UI elements, but require Espresso's main thread synchronisation! This method is mainly useful for test utilities and frameworks that are build on top of Espresso.

For UI tests use[onView(Matcher)](https://developer.android.com/reference/android/support/test/espresso/Espresso#onView(org.hamcrest.Matcher<android.view.View>))or[onData(Matcher)](https://developer.android.com/reference/android/support/test/espresso/Espresso#onData(org.hamcrest.Matcher<? extends java.lang.Object>)). These Apis already use Espresso's internal synchronisation mechanisms and do not require a call to[onIdle()](https://developer.android.com/reference/android/support/test/espresso/Espresso#onIdle()).

<br />

|                                                                                     Throws                                                                                     ||
|------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------|
| [AppNotIdleException](https://developer.android.com/reference/android/support/test/espresso/AppNotIdleException) | when app does not go Idle within the master policies timeout |

### onIdle

```
T onIdle (Callable<T> action)
```

Loops the main thread until the app goes idle.

Same as[onIdle()](https://developer.android.com/reference/android/support/test/espresso/Espresso#onIdle()), but takes an additional[Callable](https://developer.android.com/reference/java/util/concurrent/Callable.html)as parameter, which is executed after the app goes idle.

<br />

|                               Parameters                               ||
|----------|--------------------------------------------------------------|
| `action` | `Callable`: callable executed when the app goes idle. <br /> |

|                        Returns                         ||
|-----|---------------------------------------------------|
| `T` | the computed result of the action callable <br /> |

|                                                                                     Throws                                                                                     ||
|------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------|
| [AppNotIdleException](https://developer.android.com/reference/android/support/test/espresso/AppNotIdleException) | when app does not go Idle within the master policies timeout |

### onView

```
ViewInteraction onView (Matcher<View> viewMatcher)
```

Creates a[ViewInteraction](https://developer.android.com/reference/android/support/test/espresso/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.

This method builds a ViewInteraction object - it does not interact with the application under test at all. It is expected that the caller use the ViewInteraction object to perform an action or assertion.

<br />

|                        Parameters                         ||
|---------------|--------------------------------------------|
| `viewMatcher` | `Matcher`: used to select the view. <br /> |

|                                                     Returns                                                      ||
|----------------------------------------------------------------------------------------------------------|--------|
| [ViewInteraction](https://developer.android.com/reference/android/support/test/espresso/ViewInteraction) | <br /> |

**See also:**

- [onData(org.hamcrest.Matcher)](https://developer.android.com/reference/android/support/test/espresso/Espresso#onData(org.hamcrest.Matcher<? extends java.lang.Object>))  

### openActionBarOverflowOrOptionsMenu

```
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.

<br />

|         Parameters          ||
|-----------|------------------|
| `context` | `Context` <br /> |

### openContextualActionModeOverflowMenu

```
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.

<br />

### pressBack

```
void pressBack ()
```

Press on the back button.

<br />

|                                                                                                            Throws                                                                                                             ||
|------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------|
| [PerformException](https://developer.android.com/reference/android/support/test/espresso/PerformException) | if currently displayed activity is root activity, since pressing back button would result in application closing. |

### pressBackUnconditionally

```
void pressBackUnconditionally ()
```

Similar to[pressBack()](https://developer.android.com/reference/android/support/test/espresso/Espresso#pressBack())but will**not**throw an exception when Espresso navigates outside the application or process under test.

<br />

### registerIdlingResources

```
boolean registerIdlingResources (IdlingResource... resources)
```

<br />

**This method is deprecated.**   
use[register(IdlingResource)](https://developer.android.com/reference/android/support/test/espresso/IdlingRegistry#register(android.support.test.espresso.IdlingResource...))instead.

Registers one or more[IdlingResource](https://developer.android.com/reference/android/support/test/espresso/IdlingResource)s 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.

<br />

|              Parameters              ||
|-------------|-------------------------|
| `resources` | `IdlingResource` <br /> |

|                                Returns                                ||
|-----------|------------------------------------------------------------|
| `boolean` | `true`if all resources were successfully registered <br /> |

### registerLooperAsIdlingResource

```
void registerLooperAsIdlingResource (Looper looper)
```

<br />

**This method is deprecated.**   
use[registerLooperAsIdlingResource(Looper)](https://developer.android.com/reference/android/support/test/espresso/IdlingRegistry#registerLooperAsIdlingResource(android.os.Looper))instead.

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

<br />

|        Parameters         ||
|----------|-----------------|
| `looper` | `Looper` <br /> |

|                                                                   Throws                                                                   ||
|-------------------------------------------------------------------------------------------------------------|-------------------------------|
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException.html) | if looper is the main looper. |

### registerLooperAsIdlingResource

```
void registerLooperAsIdlingResource (Looper looper, 
                boolean considerWaitIdle)
```

<br />

**This method is deprecated.**   
use[registerLooperAsIdlingResource(Looper)](https://developer.android.com/reference/android/support/test/espresso/IdlingRegistry#registerLooperAsIdlingResource(android.os.Looper))instead.

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.

<br />

|              Parameters              ||
|--------------------|------------------|
| `looper`           | `Looper` <br />  |
| `considerWaitIdle` | `boolean` <br /> |

|                                                                   Throws                                                                   ||
|-------------------------------------------------------------------------------------------------------------|-------------------------------|
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException.html) | if looper is the main looper. |

### setFailureHandler

```
void setFailureHandler (FailureHandler failureHandler)
```

Changes the default[FailureHandler](https://developer.android.com/reference/android/support/test/espresso/FailureHandler)to the given one.

<br />

|                Parameters                 ||
|------------------|-------------------------|
| `failureHandler` | `FailureHandler` <br /> |

### unregisterIdlingResources

```
boolean unregisterIdlingResources (IdlingResource... resources)
```

<br />

**This method is deprecated.**   
use[unregister(IdlingResource)](https://developer.android.com/reference/android/support/test/espresso/IdlingRegistry#unregister(android.support.test.espresso.IdlingResource...))instead.

Unregisters one or more[IdlingResource](https://developer.android.com/reference/android/support/test/espresso/IdlingResource)s. If any of the given resources are not already registered, a warning is logged.

<br />

|              Parameters              ||
|-------------|-------------------------|
| `resources` | `IdlingResource` <br /> |

|                                 Returns                                 ||
|-----------|--------------------------------------------------------------|
| `boolean` | `true`if all resources were successfully unregistered <br /> |

-

  ## Interfaces

  - [EspressoException](https://developer.android.com/reference/android/support/test/espresso/EspressoException)
  - [FailureHandler](https://developer.android.com/reference/android/support/test/espresso/FailureHandler)
  - [IdlingResource](https://developer.android.com/reference/android/support/test/espresso/IdlingResource)
  - [IdlingResource.ResourceCallback](https://developer.android.com/reference/android/support/test/espresso/IdlingResource.ResourceCallback)
  - [UiController](https://developer.android.com/reference/android/support/test/espresso/UiController)
  - [ViewAction](https://developer.android.com/reference/android/support/test/espresso/ViewAction)
  - [ViewAssertion](https://developer.android.com/reference/android/support/test/espresso/ViewAssertion)
  - [ViewFinder](https://developer.android.com/reference/android/support/test/espresso/ViewFinder)
  - [ViewInteractionComponent](https://developer.android.com/reference/android/support/test/espresso/ViewInteractionComponent)
-

  ## Classes

  - [AmbiguousViewMatcherException.Builder](https://developer.android.com/reference/android/support/test/espresso/AmbiguousViewMatcherException.Builder)
  - [DataInteraction](https://developer.android.com/reference/android/support/test/espresso/DataInteraction)
  - [DataInteraction.DisplayDataMatcher](https://developer.android.com/reference/android/support/test/espresso/DataInteraction.DisplayDataMatcher)
  - [Espresso](https://developer.android.com/reference/android/support/test/espresso/Espresso)
  - [IdlingPolicies](https://developer.android.com/reference/android/support/test/espresso/IdlingPolicies)
  - [IdlingPolicy](https://developer.android.com/reference/android/support/test/espresso/IdlingPolicy)
  - [IdlingRegistry](https://developer.android.com/reference/android/support/test/espresso/IdlingRegistry)
  - [NoMatchingViewException.Builder](https://developer.android.com/reference/android/support/test/espresso/NoMatchingViewException.Builder)
  - [PerformException.Builder](https://developer.android.com/reference/android/support/test/espresso/PerformException.Builder)
  - [Root](https://developer.android.com/reference/android/support/test/espresso/Root)
  - [Root.Builder](https://developer.android.com/reference/android/support/test/espresso/Root.Builder)
  - [ViewInteraction](https://developer.android.com/reference/android/support/test/espresso/ViewInteraction)
-

  ## Exceptions

  - [AmbiguousViewMatcherException](https://developer.android.com/reference/android/support/test/espresso/AmbiguousViewMatcherException)
  - [AppNotIdleException](https://developer.android.com/reference/android/support/test/espresso/AppNotIdleException)
  - [IdlingResourceTimeoutException](https://developer.android.com/reference/android/support/test/espresso/IdlingResourceTimeoutException)
  - [InjectEventSecurityException](https://developer.android.com/reference/android/support/test/espresso/InjectEventSecurityException)
  - [NoActivityResumedException](https://developer.android.com/reference/android/support/test/espresso/NoActivityResumedException)
  - [NoMatchingRootException](https://developer.android.com/reference/android/support/test/espresso/NoMatchingRootException)
  - [NoMatchingViewException](https://developer.android.com/reference/android/support/test/espresso/NoMatchingViewException)
  - [PerformException](https://developer.android.com/reference/android/support/test/espresso/PerformException)