Android Testing UI with Espresso Overall Espresso

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Setup Espresso :

androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test:runner:0.5'

ViewMatchers – A collection of objects that implement Matcher<? super View> interface. You can pass one or more of these to the onView method to locate a view within the current view hierarchy.

ViewActions – A collection of ViewActions that can be passed to the ViewInteraction.perform() method (for example, click()).

ViewAssertions – A collection of ViewAssertions that can be passed the ViewInteraction.check() method. Most of the time, you will use the matches assertion, which uses a View matcher to assert the state of the currently selected view.


Espresso cheat sheet by google

enter image description here


Enter Text In EditText

onView(withId(R.id.edt_name)).perform(typeText("XYZ"));
        closeSoftKeyboard();

Perform Click on View

 onView(withId(R.id.btn_id)).perform(click());

Checking View is Displayed

 onView(withId(R.id.edt_pan_number)).check(ViewAssertions.matches((isDisplayed())));


Got any Android Question?