Questions tagged [android-espresso]

Espresso is a library which is used to write Android UI tests. It is also known as Google's Testing Tools For Android

Also called android-test-kit, Espresso helps to create faster UI tests for Android.

The core API is small, predictable, and easy to learn and yet remains open for customization. Espresso tests state expectations, interactions, and assertions clearly without the distraction of boilerplate content, custom infrastructure, or messy implementation details getting in the way.

Espresso tests run optimally fast! Leave your waits, syncs, sleeps, and polls behind and let Espresso gracefully manipulate and assert on the application UI when it is at rest. Enjoy writing and executing your tests today - try a shot of Espresso!

Useful links

3335 questions
75
votes
13 answers

Android Marshmallow: Test permissions with Espresso?

The new permissions scheme introduced by Android Marshmallow requires checking for specific permissions at runtime, which implies the need to provide different flows depending on whether the user denies or allows access. As we use Espresso to run…
argenkiwi
  • 2,134
  • 1
  • 23
  • 26
71
votes
8 answers

How to count RecyclerView items with Espresso

Using Espresso and Hamcrest, How can I count items number available in a recyclerView? Exemple: I would like check if 5 items are displaying in a specific RecyclerView (scrolling if necessary).
Boris S.
  • 1,068
  • 1
  • 8
  • 18
70
votes
10 answers

Espresso - How to check if one of the view is displayed

In my test, after one action, there are two possible views which can appear and both of them are correct. How can I check if one of the view is displayed. For a single view I can check with is Displayed(). But that would fail if other view is…
user846316
  • 6,037
  • 6
  • 31
  • 40
67
votes
10 answers

In Espresso, how to avoid AmbiguousViewMatcherException when multiple views match

Having gridView which has some images. The gridView's cell comes out from same predefined layout, which has same id and desc. R.id.item_image == 2131493330 onView(withId(is(R.id.item_image))).perform(click()); Since all cells in the grid have…
lannyf
  • 9,865
  • 12
  • 70
  • 152
62
votes
8 answers

Espresso - How can I check if an activity is launched after performing a certain action?

the following is one of my Espresso test cases. public void testLoginAttempt() { Espresso.onView(ViewMatchers.withId(R.id.username)).perform(ViewActions.clearText()).perform(ViewActions.typeText("nonexistinguser@krossover.com")); …
user2062024
  • 3,541
  • 7
  • 33
  • 44
57
votes
2 answers

registerIdlingResources deprecation replacement doesn't work

I'm trying to replace my Espresso registerIdlingResources and unregisterIdlingResources deprecated method by using IdlingRegistry method according to Android documentation. Some of my tests worked before the update and no longer work now. These…
Crisic
  • 1,181
  • 1
  • 9
  • 27
56
votes
11 answers

Get Current Activity in Espresso android

In case of a test that crosses multiple activities, is there a way to get current activity? getActivtiy() method just gives one activity that was used to start the test. I tried something like below, public Activity getCurrentActivity() { …
fenrigne123
  • 593
  • 1
  • 4
  • 9
51
votes
3 answers

Testing Snackbar show with Espresso

Is there a way to test using Espresso that the snackbar shows up with the right text? I have a simple call to create a snackbar Snackbar.make(mView, "My text", Snackbar.LENGTH_LONG).show(); I have tried this without luck onView(withText("My…
50
votes
4 answers

Testing multiple activities with espresso

Is it possible to write tests across several activities using the android espresso framework?
fernandohur
  • 7,014
  • 11
  • 48
  • 86
49
votes
8 answers

Espresso: return boolean if view exists

I am trying to check to see if a view is displayed with Espresso. Here is some pseudo code to show what I am trying: if (!Espresso.onView(withId(R.id.someID)).check(doesNotExist()){ // then do something } else { // do nothing, or what have…
Chad Bingham
  • 32,650
  • 19
  • 86
  • 115
48
votes
14 answers

Click home icon with Espresso

I am trying to click the home icon in some Espresso tests via: onView(withId(android.R.id.home)).perform(click()); This works fine for Android > 3.0 - but fails for older versions as appcompat does not seem to use this id for this element then.…
ligi
  • 39,001
  • 44
  • 144
  • 244
48
votes
5 answers

Updating an EditText with Espresso

I'm attempting to update an EditText as part of an Espresso test with: onView(allOf(withClassName(endsWith("EditText")), withText(is("Test")))).perform(clearText()) …
user1596371
48
votes
7 answers

Error=Unable to find instrumentation info for: ComponentInfo{ }

I am trying to stand up espresso tests but I keep getting this error: INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{com.mikeestrada.test/android.test.InstrumentationTestRunner} It worked once, but I can't get…
mikeestrada67
  • 491
  • 1
  • 4
  • 4
45
votes
2 answers

JUnit4 - AssertionFailedError: No tests found

I'm using AndroidJUnitRunner with Espresso. I wrote a simple test but always receive this exception. According to Stackoverflow answers, the problem is messing up the JUnit3 and JUnit4 but I have never used JUnit3 in my…
Val
  • 4,225
  • 8
  • 36
  • 55
44
votes
8 answers

Espresso, scrolling not working when NestedScrollView or RecyclerView is in CoordinatorLayout

It looks like CoordinatorLayout breaks the behaviour of Espresso actions such as scrollTo() or RecyclerViewActions.scrollToPosition(). Issue with NestedScrollView For a layout like this one: