-
Notifications
You must be signed in to change notification settings - Fork 0
Espresso concepts
Devrath edited this page May 17, 2021
·
10 revisions
Title |
---|
The espresso formulae |
Why to use onView instead of findViewById |
Fluent API |
Hamcrest Matcher |
Hamcrest cheat sheet |
- The espresso formulae consist of three parts
ViewMatcher
<--->
ViewAction
<--->
ViewAssertion
onView(ViewMatcher) // Locate a view on the screen.
.perform(ViewAction) // Perform a action on the screen like clicking, typing etc.
.check(Assertion) // Also we can can check that whether it works as expected.
- This is because of
synchronization
. - By using
onView
, the espresso will wait for the application to become idle and then perform the test, Otherwise, the application will beflaky
. This ensures that the views are properly rendered and there are no pendingasync tasks
- If we use
findViewById
, the app loses the synchronization event that may trigger before the UI is rendered.
- Once we have a reference with the help of
OnView
we can chain any number of actions until it is pertaining to that particular view because each action returns aview-interaction
.
We can use the hamcrest matcher
in combination with the espresso
to perform certain test actions.