Is there a reliable way to make Espresso wait for WebViews to finish loading?
I've tried the approach outlined here but found it unreliable. It also has other drawbacks:
I'm hoping someone has a solution without any of these drawbacks. I had hopes that the espresso-web package might provide a solution, but it doesn't appear to offer anything relating to loading.
WebView is a special view provided by android to display web pages inside the application. WebView does not provide all the features of a full-fledged browser application like chrome and firefox. However, it provides complete control over the content to be shown and exposes all the android features to be invoked inside the web pages.
While waiting for a view to show up is usually handled by espresso itself, there might be cases where your app is doing work on another thread (fetching data from a server, calculating something) and therefore espresso does not know about it. There are different ways to handle this, most commonly idling resources.
onWebView () − Similar to onView (), it exposes a set of API to test a WebView. withElement () − One of the several methods used to locate web elements inside a web page using Atom and returns WebInteration object, which is similar to ViewInteraction. perform () − Executes the action inside a web page using Atom and returns WebInteraction.
As you mentioned, there is an espresso add-on called espresso-web for dealing with webviews and their content.
"finish loading" is a bit of a vague concept. It will depend on what specifically to you want to finish.
If you use onWebView().check(<the you want to finish is in your webview>)
that will return only after the web view has loaded and the check
has succeeded.
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.
https://developer.android.com/training/testing/espresso/web
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With