Express Automation Using
Espresso
➢ What and how
➢ Components of espresso
➢ Extensions and others
➢ Pros and cons
WHAT
● A UI test framework (part of the Android
Testing Support Library)
● To create automated UI tests for Android
app
● Gradle + Android Studio support
● Simple and Extensible API remains open
for customization
HOW
● Install android support repository
● In build.gradle dependencies
androidTestCompile 'com.android.support.test.espresso:espresso-
core:2.2.2'
androidTestCompile 'com.android.support.test:runner:0.5'
● Under default config
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
● Create class with
@RunWith(AndroidJUnit4.class)
● Specify Activity to be tested with @Rule and Create test functions with
@Test
Main components of Espresso :
● Espresso – Entry point to interact with views and APIs not tied
to view
● ViewMatchers – To identify view within view hierarchy
● ViewActions – Do action on view
● ViewAssertions – Verify or Assert on view
● OnView
● OnData
● PressBack
● CloseSoftKeyboard
Espresso
withId(R.id.error_msg)
withContentDescription("More options")
allOf(withId(R.id.error_msg_text),withEffectiveVisibility(ViewMatche
rs.Visibility.VISIBLE)
allOf(withId(R.id.count),
hasSibling(withText(R.string.summary_header)
ViewMatchers
● Perform(click(.....))
● Perform(ScrollTo(....))
● Perform(replaceText(....))
● Perform(swipeRight(....))
ViewActions
check(matches(withText(quantity)))
check(matches(withChild(withText(message))))
check(matches(hasDescendant(withText(heading))))
check(doesNotExist())
check(matches(isDisplayed()))
ViewAssertions
atPosition()
- onData(...).atPosition(2).perform(click());
inRoot()
- toast message checking
- prompts etc...
onChildView()
Data Interaction
● GetChildCount()
● SetMobileData()
● ScanActions()
● SetProfile()
Extensible & Customizable
● Webview
● StubTesting using Intent and ServiceTestRule
● Extend to test performance, memory leakage ...
● Pretty reports
Others
● API is small, predictable and easy to learn
● Support from API level 8 (Froyo)
● Light weight, Fast and Reliable test
● Rich failure information and customizable
failure handling
● Automatic synchronization of test actions
loopmainthreaduntilidle
● Can use UI automator methods
● Runs on actual device or emulator, mimics user
WHY
● Application push notifications
● Sync Test
● Navigating from another app to your app
● Extending test to other OS
WHAT NOT
● http://developer.android.com/
● https://github.com/codepath/android_guides/wiki/UI
● https://google.github.io/android-testing-support-libra
Reference
● http://developer.android.com/
● https://github.com/codepath/android_guides/wiki/UI
● https://google.github.io/android-testing-support-libra

Espresso