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
30
votes
2 answers

Unresolved reference ActivityTestRule for AndroidX

I'm trying to test my UI via instrumentation test, with androidX espresso library. In my grade I have: apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin:…
Nicola Gallazzi
  • 7,897
  • 6
  • 45
  • 64
30
votes
10 answers

How to test TextInputLayout values (hint, error, etc.) using Android Espresso?

I am trying to test using Espresso if my TextInputLayout views have specific hint. I'd used a code as below: Espresso.onView(ViewMatchers.withId(R.id.edit_text_email)) .check(ViewAssertions.matches( …
Elye
  • 53,639
  • 54
  • 212
  • 474
29
votes
4 answers

Android Espresso: How do I test a specific Fragment when following one activity to several fragment architecture

My app consists of one Activity for many Fragments. I wish to use Espresso to test the UI of the Fragments. However I ran into a problem. How can I test a Fragment which is not added to an Activity in onCreate. All examples I have seen with…
Ersen Osman
  • 7,067
  • 8
  • 47
  • 80
29
votes
7 answers

How to rotate activity, I mean: screen orientation change using Espresso?

I have decided that one of the testing criteria for my application tests with Google's Espresso is: Test should maintain Activity state after screen orientation rotation How do I rotate the screen when using Espresso? I have tried the following…
FalconBot
  • 419
  • 1
  • 4
  • 12
29
votes
1 answer

Using Espresso to Unit Test Google Maps

I am using Espresso to do some UI testing on my app. I have a fragment with a map, and I display some items on it that I get through a call to my backend. When I click on a marker, I'm doing some UI things Is there any way I can do unit testing on…
user2230304
  • 578
  • 1
  • 5
  • 14
29
votes
2 answers

how to get text from textview using espresso

I want get text string shown in a textview in LinearLayout. can espresso do that? If not, is there other way to do that or can I use android api in espresso test case? I am using API 17 18 or newer, espresso 1.1(It should be the latest one.). I have…
Nick Dong
  • 3,638
  • 8
  • 47
  • 84
28
votes
1 answer

Android Studio Espresso Test Recorder Slow

I am trying to create some Espresso UI tests using Android Studio's inbuilt Espresso Test Recorder. The issue is: when I type it is very slow to appear on the screen. Anything text entry/keyboard-based takes a while for a single letter to appear. I…
Calco
  • 1,420
  • 1
  • 17
  • 31
28
votes
8 answers

How to disable the new Autofill feature from Android Oreo for espresso tests

Running tests on android devices with sdk 26 causes them to fail because of the new Autofill feature that hides the fields when espresso are trying to click them. Im running my tests on firebase test lab so I cannot disable them manually on my tests…
28
votes
1 answer

How to obtain coverage for Android project using Espresso tests

I used to write Android tests using Robotium and retrieve the coverage using Emma. Recently I changed to use Espresso tests and I'm having troubles to retrieve coverage of Instrumentation tests. I can only retrieve coverage for Unit tests that use…
28
votes
12 answers

How to manage Runtime permissions android marshmallow espresso tests

I'm using espresso for testing but sometimes I try to get an image form external storage and with marshmallow I need a Runtime permission otherwise there will be an Exception crash and the test will fail. androidTestCompile…
Daniel Gomez Rico
  • 15,026
  • 20
  • 92
  • 162
27
votes
2 answers

Cannot resolve ActivityTestRule after upgrading dependencies. Unable to import ActivityTestRule

I have written instrumentation tests which was working fine, but now getting error cannot resolve ActivityTestRule error after upgrading dependencies to androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation…
27
votes
6 answers

Android Espresso - Click checkbox if not checked

I have onView(withId(R.id.check_box)).perform(click()), but i only want to do this if the check box is not already checked. How can I do this in espresso?
kyrax
  • 1,192
  • 3
  • 13
  • 29
27
votes
4 answers

Android Espresso testing 'Cannot resolve symbol 'InstrumentationRegistry''

I'm trying to import import android.support.test.InstrumentationRegistry; my build.gradle file androidTestCompile 'com.android.support.test:testing-support-lib:0.1' androidTestCompile…
Adz
  • 2,809
  • 10
  • 43
  • 61
27
votes
2 answers

What is touch mode and why is it important for the ActivityTestRule class?

The ActivityTestRule class takes in an initialTouchMode parameter in its constructor. This is not explained in the class reference (or anywhere online) except as follows: initialTouchMode - true if the Activity should be placed into "touch mode"…
27
votes
4 answers

Espresso startActivity that depends on Intent

I have the following situation. My activity has a fragment that depends of a Serializable Object. Here is my onCreate: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MyObject myObj =…
rafael
  • 732
  • 1
  • 11
  • 20