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
34
votes
4 answers

Android Espresso check selected spinner text

I have this code in my Espresso test onView(withId(R.id.src)) .perform(click()); onData(hasToString(startsWith("CCD"))) .perform(click()); onView(withId(R.id.src)) .check(matches(withText(containsString("CCD")))); What I'm trying to do…
Jezer Crespo
  • 2,152
  • 3
  • 24
  • 27
34
votes
5 answers

Can I extend a custom Application in Espresso?

I'm attempting to set up Dagger in my Espresso instrumentation tests in order to mock out calls to external resources (RESTful services in this case). The pattern I followed in Robolectric for my unit testing was to extend my production Application…
Jim Kirkbride
  • 379
  • 1
  • 4
  • 7
33
votes
2 answers

I can't make ViewActions.closeSoftKeyboard() work in Espresso 2.2.2

I'm trying to test an app and I require to hide the keyboard, because I cannot click button because of it. So, I added Espresso in build.gradle: androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2' and tried to use this from…
getsadzeg
  • 640
  • 3
  • 9
  • 19
33
votes
8 answers

Espresso how to test if Activity is finished?

I want to assert that my Acitivty that I am currently testing is finished when certain actions are performed. Unfortunately so far I am only to assert it by adding some sleep at the end of the test. Is there a better way ? import…
33
votes
10 answers

How to detect whether android app is running UI test with Espresso

I am writing some Espresso tests for Android. I am running in the the following problem: In order for a certain test case to run properly, I need to disable some features in the app. Therefore, in my app, I need to detect whether I am running…
Comtaler
  • 1,580
  • 1
  • 15
  • 26
33
votes
7 answers

Test order with espresso

Is there a way to set test running order in android? I use Espresso framework and need to test a lot of activities and transitions between them. I want to write different test for those activities, but I need a specific order for running those…
mr. Nutscracker
  • 545
  • 1
  • 4
  • 11
32
votes
2 answers

Espresso generating FileNotFoundException, when used with Dagger

I have been wrestling with a legacy Android app, attempting to add testing and proper architecture to it. The app has a main LaunchActivity which runs a series of checks on launch. Originally, the activity was using Dagger to, rather poorly, 'inject…
32
votes
2 answers

Espresso.pressBack() does not call onBackPressed()

In Espresso class: @Rule var mIntentsRule = IntentsTestRule(MainActivity::class.java) @Test fun test_backButton() { onView(withId(R.id.NEXT_ACTIVITY)).perform(scrollTo(), click()) Espresso.pressBack() } In Activity: @Override public void…
billst
  • 649
  • 1
  • 8
  • 14
32
votes
4 answers

Espresso match first element found when many are in hierarchy

I'm trying to write an espresso function to match the first element espresso finds according to my function, even when multiple matching items are found. Ex: I have a list view with cells which contain item price. I want to be able to switch the…
Bebop_
  • 645
  • 2
  • 6
  • 9
32
votes
2 answers

Make Espresso wait for WebView to finish loading

Is there a reliable way to make Espresso wait for WebViews to finish loading? I've tried the approach outlined here but found it unreliable. It also has other drawbacks: It relies on replacing the WebView's WebChromeClient. Any existing…
vaughandroid
  • 4,315
  • 1
  • 27
  • 33
32
votes
4 answers

Espresso: how to scroll to the bottom of ScrollView

How is it possible to scroll down to the bottom of ScrollView in Espresso test? Thanks!
Kid24
  • 4,401
  • 4
  • 23
  • 19
32
votes
5 answers

Start Activity for testing

I 've got a Quiz app using Realm db. Every time the user selects an answer she clicks a button and new text for Question appears. Thats it until she reaches the end where I start a new Activity and display a score based on correct answers. How…
t0s
  • 1,201
  • 5
  • 19
  • 28
31
votes
3 answers

Espresso test recording feature in Android Studio 2.2

In Android Studio 2.2 there is supposed to be a test recording function? Where do I find it and how do I use it?
31
votes
3 answers

Android Studio Instrumentation testing build variant

So I am trying to write instrumentation tests using a custom build variant, mock. In this build variant I mocked up my classes and server. When I try using the mock build myself it works fine, but I can't seem to use my mock build for testing.…
31
votes
3 answers

Click by bounds / coordinates

I know it is possible for Espresso to click by bounds the way UiAutomator does. (x and y coordinates) I have read through the documentation but I can't seem to find it. Any help is appreciated. Thanks Edit I found this link, but no examples how to…
Chad Bingham
  • 32,650
  • 19
  • 86
  • 115