android - 让 Espresso 等待 WebView 完成加载

标签 android testing webview android-espresso

有没有可靠的方法让 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.

https://developer.android.com/training/testing/espresso/web

关于android - 让 Espresso 等待 WebView 完成加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32070359/

相关文章:

android - 如何使用多个 Horizo​​ntalListView 填充布局

android - 如何降低 Google Map Api 成本或优化跟踪和 api 命中的方法

java - jubula 和访问后端数据库

testing - 问测试 "meta"问题的好地方是什么?

Android,加载数据后将webview滚动到Y位置

cocoa - 重新打开 NSWindow 后 WebView 空白

android - 如何在 Android Imageview 中平滑移动图像

java - 背景淡出并转到另一个页面

mongodb - 如何使用 Scala 将 1 亿条记录加载到 MongoDB 中进行性能测试?

java - 使用javafx在Web View 中查看嵌入Flash源的html文件