【问题标题】:How to handle app redirects to browser in appium?如何在appium中处理应用重定向到浏览器?
【发布时间】:2015-12-13 22:44:40
【问题描述】:

我在测试中卡住了应用程序重定向到浏览器页面进行付款的步骤。付款页面打开后显示:

no such element: Unable to locate element:

我知道元素的 id 是正确的。据我了解,我无法切换到浏览器。
当我尝试使用 driver.switch_to.window(); 时,Appium 会出错,我猜它在 appium 上不起作用。 (至于我想的 Windows 上的 android。它说它还没有实现)
任何帮助将不胜感激。

【问题讨论】:

    标签: android redirect browser appium


    【解决方案1】:

    在这里,被测应用可以称为混合应用,其中应用的业务逻辑由Web services处理。在这种情况下,处理付款

    您通过允许驱动程序切换到某物来非常正确地接近它。只有在移动应用程序自动化的情况下,我们有以下方法(假设您使用的是带有 Java 的 appium):

    public void appTest() throws InterruptedException{
    
                Set<String> text = ((AndroidDriver) driver).getContextHandles();
                  System.out.println(text);   
                 for (String contexts : text) {
                  if (contexts.contains("WEBVIEW_com.hk8securities.app8now"))
                  {
                 ((AndroidDriver) driver).context(contexts);
                  System.out.println(contexts);
                  }
                  else{
                      System.out.println("not switched");
                  }
                 }
      }
    

    为了了解可用的上下文,请先在控制台上打印它们,然后再切换到它。 根据我的观察,在 android 中它返回 NATIVE_APP,WEBVIEW_WEBVIEWNAME。在 iPhone 中,它不提供 webview/s 的名称,而只提供 WEBVIEW_1/2/3 等。此外,这些数字会不断改变您运行测试的次数。

    希望这将有助于您入门。

    【讨论】:

    • 在几秒钟测试崩溃后发现第一个上下文包括 WEBVIEW 时,它会卡住。我无法管理它,但无论如何谢谢。
    猜你喜欢
    • 2019-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-06
    • 1970-01-01
    • 2016-08-29
    • 2012-12-19
    • 1970-01-01
    相关资源
    最近更新 更多