简体   繁体   English

如何在java中使用appium和selenium处理webview

[英]How to handle webview using appium and selenium with java

I am doing testing on Amazon android app for learning purpose.我正在亚马逊 android 应用程序上进行测试以进行学习。 I have done few basic test cases and executes it successfully.我已经完成了一些基本的测试用例并成功执行了它。 Now i want to login but I don't know how to handle webview in appium and selenium with java.现在我想登录,但我不知道如何使用 java 在 appium 和 selenium 中处理 webview。 Please help me.请帮我。

This code is just for switching from native app context to webview context,此代码仅用于从本机应用程序上下文切换到 webview 上下文,

get all context in this case webView and native app在这种情况下获取所有上下文 webView 和本机应用程序

Set<String> contextNames = driver.getContextHandles();

for (String contextName : contextNames) {
    System.out.println(contextNames); 
}
driver.context(contextNames.toArray()[1]);

//switch to inapp webview, and do Your stuff, if webview is enabled for automation

String myText = driver.findElement(By.cssSelector("buttonId")).click();

driver.context("NATIVE_APP");

//switch back to app

and here is a link how to locate and list elements in webView, here is a nice article how to connect to webView via Chrome on remote device (Android)这是如何在 webView 中定位和列出元素的链接,这是一篇很好的文章如何通过远程设备(Android)上的 Chrome 连接到 webView

[ https://developers.google.com/web/tools/chrome-devtools/remote-debugging/?utm_source=dcc&utm_medium=redirect&utm_campaign=2016q3] [ https://developers.google.com/web/tools/chrome-devtools/remote-debugging/?utm_source=dcc&utm_medium=redirect&utm_campaign=2016q3]

So You could check elements and if it enabled for automation testing.所以你可以检查元素以及它是否启用了自动化测试。

To switch to webView in your android app, webView debugging should be enabled in your app.要在您的 android 应用程序中切换到 webView,应在您的应用程序中启用webView 调试 For Amazon android app webView is not enabled.对于 Amazon android 应用程序 webView 未启用。 You can refer this link你可以参考这个链接

You can develop your own android app by enabling remote debugging webView or you can use chrome browser which comes with webView enabled.您可以通过启用远程调试 webView 来开发自己的 android 应用程序,也可以使用启用了 webView 的 chrome 浏览器。

To switch to WebView :切换到 WebView :

Set<String> contextNames = driver.getContextHandles();
    for(String context : contextNames) {
        if(context.contains("WEBVIEW")){
            System.out.println("Context Name is " + context);
            driver.context(context);                
            break;
        }
    }       

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM