Espresso-web is an entry point to work with WebViews on Android. It uses Atoms from the popular WebDriver API to introspect into and control the behavior of a WebView.
Similar to onData, WebView interactions are actually composed of several View Atoms. An Atom can be seen as a ViewAction, a self contained unit which performs an action in your UI. However, they need to be properly orchestrated and are quite verbose. Web and WebInteraction wrap this boilerplate and give an Espresso-like feel to interacting with WebViews.
withElement(ElementReference)will supply the
ElementReferenceto the Atom. Example:
withContextualElement(Atom<ElementReference>)will supply the ElementReference to the Atom. Example:
check(WebAssertion)will evaluate an assertion. Example:
perform(Atom)will execute the provided atom within the current context. Example:
reset()is necessary when a prior action (for example a click) introduces a navigation change that invalidates the ElementReference and WindowReference pointers.
See the Espresso Web sample on GitHub.
- Make sure you have installed the Android Support Repository (see instructions).
- Open your app’s
build.gradlefile. This is usually not the top-level
Add the following line inside dependencies:
Espresso-Web is only compatible with Espresso 2.2+ and the testing support library 0.3+ so make sure you update those lines as well: