【问题标题】:Appium Android AutomationAppium Android 自动化
【发布时间】:2015-10-19 11:49:37
【问题描述】:

对于专家来说,这可能是一个简单的问题。我是 appium 的初学者,这些天我一直在尝试制作我的测试脚本以在我的脚本中打印页面标题。这是下面我的代码的一部分:我无法打印页面标题然后进行验证。有人可以帮忙吗?

driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
      System.out.println(driver.getRemoteAddress()); 
}

public void ApkPushValidation() throws Exception {

Assert.assertEquals("Verify your phone number", driver.findElementByName("Verify your phone number").getText());

    driver.wait(5000);
    String i = driver.getTitle();
    System.out.println(i);


if (driver.getTitle().equals("Verify your phone number") ) {

    System.out.println("app installation is passed");

} else {

System.out.println("App installation is failed");

}

//System.out.println(i);---> my expectation is that this will print out Verify your Phone number. However this is not printing the page title.

【问题讨论】:

    标签: android appium mobile-application


    【解决方案1】:

    使用 UIAutomatorViewer 找出标题的 xpath。

    以以下网站为例,了解如何使用 x-path。 "http://software-testing-tutorials-automation.blogspot.ca/2015/10/ui-automator-viewer-get-android-app.html"

    【讨论】:

      【解决方案2】:

      我认为driver.getTitle() 是一种用于网页交互的方法,不适用于本机应用程序。我建议使用 XPath 或其他一些元素定位器来查找标题。

      【讨论】:

      • 您是说在按名称查找元素之前添加 driver.wait 吗?如果是,那么它也不起作用。运行后出现控制台错误:
      • 失败:ApkPushTest org.openqa.selenium.WebDriverException:尚未实现。请帮助我们:appium.io/get-involved.html(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:16 毫秒
      • 您提供的日志证实了我的怀疑。此方法暂不打算使用。
      • 感谢@Kristaps Mezavilks。正如你所说的,getTitle() 方法尚未实现。
      【解决方案3】:

      如果getTitle(); 尝试使用可用于标题的xPath、名称或ID,则相反。使用 Appium 检查器或 UI 自动化器来定位该元素并像这样进行更改:

      String i = driver.findElementById("Your ID").getText();
      if (i.equals("Verify your phone number") ) {
          System.out.println("app installation is passed");
      
      } else {
      
      System.out.println("App installation is failed");
      
      }
      

      【讨论】:

      • 谢谢高拉夫。好吧,我使用 AssertEquals 方法来验证预期的字符串并且它有效。
      【解决方案4】:

      您可能要执行的操作应该使用以下代码来完成:

      WebElement title = driver.findElementByName("Verify your phone number"); // defining the element only once for multiple use
      // different locator strategies could be used for locating the element above
      
      Assert.assertEquals("Verify your phone number", title.getText());  
      driver.wait(5000);
      String i = title.getText();
      System.out.println(i);    
      if (i.equals("Verify your phone number") ) {
          System.out.println("app installation is passed");
      } else {
          System.out.println("App installation is failed");
      }
      

      关于driver.getTitle() 的更多信息:它继承自RemoteWebDriver,并且可能应该返回网页/webview 的标题,而不是您的情况的本机应用程序视图。

      注意:据我所知,会添加更多关于 getTitle() 的内容。

      【讨论】:

        猜你喜欢
        • 2017-12-20
        • 2020-06-23
        • 1970-01-01
        • 2014-01-31
        • 2016-08-23
        • 2016-12-27
        • 2019-10-05
        • 2016-06-24
        • 1970-01-01
        相关资源
        最近更新 更多