gpt4 book ai didi

java - Espresso-web 检查网页元素不存在

转载 作者:行者123 更新时间:2023-11-30 01:08:34 24 4
gpt4 key购买 nike

我正在使用 espresso-web 来测试我的 android 应用程序中的 webview。我想测试一个元素不存在。如何做到这一点?

背景:我们有一个 Web 服务,可以将页面传送到我们的移动网站以及 Android 应用程序中的 webview。由于 Android 应用程序有它自己的 actionbar,我们不希望在移动设备上的浏览器中打开页面时显示页面中显示的标题。

对于其他非webviews,我已经能够使用以下代码来测试未显示 native 元素。

ViewInteraction logoutView = onView(
allOf(withId(R.id.account_logout), withText("logout"), isDisplayed()));

logoutView.check(doesNotExist());

我希望类似下面的东西能起作用

Web.WebInteraction<Void> mobileWebHeader =  onWebView().   
withElement(findElement(Locator.TAG_NAME, "header"));
mobileWebHeader.check(doesNotExist());

不幸的是它没有,我还没有找到任何替代品。

提前致谢!

最佳答案

在这种情况下,我找不到比使用 try/catch 更好的解决方案:

try {
onWebView().withElement(findElement(Locator.TAG_NAME, "header"));
} catch (RuntimeException notExist) {
//good!
}

关于java - Espresso-web 检查网页元素不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38657727/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com