有没有可靠的方法让 Espresso 等待 WebView 完成加载?
我已经尝试了 here 概述的方法但发现它不可靠。它还有其他缺点:
- 它依赖于替换 WebView 的 WebChromeClient。任何现有的 WebChromeClient 也不能被包装,因为 WebViewrt 出于某种原因没有 getWebChromeClient() 方法。
- 它需要一个特定的 WebView 实例,因此每次我使用 WebView 启动 Activity 时,我都必须获取 WebView 实例并为其注册一个新的 WebviewIdlingResource。
我希望有人能找到没有这些缺点的解决方案。我曾希望 espresso-web 包可以提供解决方案,但它似乎没有提供与加载相关的任何内容。
最佳答案
正如您所提到的,有一个名为 espresso-web 的 espresso 插件,用于处理 webview 及其内容。
“完成加载”是一个有点模糊的概念。这将取决于您想要完成的具体什么。
如果您使用 onWebView().check(<the you want to finish is in your webview>)
只有在 web View 加载和 check
之后才会返回成功了。
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.
关于android - 让 Espresso 等待 WebView 完成加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32070359/