"autoWebView" APPIUM 功能是否保证 WEB_VIEW 与 cordova 应用程序相关的多个 webviews 正确?

Does "autoWebView" APPIUM capability guarantee correct WEB_VIEW out of multiple webviews ,in relation to cordova app?

我正在使用 Appium-Java 自动化 iOS 应用程序。

在 appium 文档中提到- "autoWebView" APPIUM 功能应该用于基于 Cordova 的应用程序

在我们的例子中,随着用户继续浏览屏幕,应用程序不断堆叠多个 WebView。 在那种情况下,通常我有 1 个本机视图和 3-4 个 Web 视图。 因此,如果我设置 autoWebView,它是否会保证 - 它始终指向正确的 webview(即 webview,其中包含当前页面的 HTML)

希望您使用 ios_webkit_debug_proxy 来处理嵌入在 ios 本机应用程序中的 webview。每当应用程序页面发生变化("NATIVE" 或 "WEBVIEW")时,还要相应地在脚本中切换上下文。

看看这个linkhttps://github.com/google/ios-webkit-debug-proxy

为了我们的独特需求(基于 Cordova 的混合应用程序创建多个 webview),我创建了一个可重用的函数来指向预期的 WebView:

 public boolean switchToMeaningfulWEBVIEWUsingPageTitle(final String title) {
    Set<String> contextNames = appiumDriver.getContextHandles();
    List<MobileElement> elements = null;

    String defaultContext = appiumDriver.getContext();

    for (String contextName : contextNames) {
            System.err.println("\n ** DEBUG: contextName = "+contextName);
        appiumDriver.context(contextName);
        appiumDriver.manage().timeouts().implicitlyWait(6, TimeUnit.SECONDS);
        if (contextName.contains("WEBVIEW")) {
            String metaTitle = appiumDriver.getTitle();
            if (metaTitle.equalsIgnoreCase(title)) {
                if(appiumDriver.getPageSource().trim().contains("<body></body></html>")) {
                    continue;
                }else{
                    return true;
                }
            }
        }
    }
   appiumDriver.context(defaultContext);
    return false;
}

基本上当我们要对最新页面的WebView进行一些操作时,我们会从Webview的Stack中切换到相关的webView。 Html 标题用作参考,因为我们尽量保持其独特性,但也可以使用其他内容作为唯一参考。谢谢