【问题标题】:Calabash-android: Touch fails due to "No elements found" but element was foundCalabash-android:由于“未找到元素”,触摸失败,但找到了元素
【发布时间】:2014-08-28 11:06:56
【问题描述】:

我正在使用 calabash-android-java 测试使用 Xamarin 构建的混合应用程序。正如您在下面看到的,我能够查询 DOM 元素,甚至可以将一些信息记录到控制台,但是当我执行 touch 命令时,无论出于何种原因,都无法再找到该元素。

我查看了 calabash-android-java source code 中的故障点,但它似乎只是将我的查询传递给了脚本引擎,这是我所能接受的。

我只是误解了触摸命令的使用吗?我认为它应该能够“触摸”锚标记,但也许不能?

无论如何,我们将不胜感激任何帮助......我的 Google fu 今天让我失望了。

HTML

<div style="width: 100px">
    <a data-role="button" ng-click="submit()" id="loginButton">Log In</a>
</div>

Java

@When("^user \"(.*?)\" logs in with valid credentials$")
public void user_logs_in_with_valid_credentials(String username) throws Throwable {
    UIElement login = app.query("webView css:'#loginButton'").first();
    System.out.println("Element_Id=" + login.getId());
    System.out.println("Element_Class=" + login.getElementClass());
    System.out.println("Element_Query=" + login.getQuery());
    System.out.println("Element_Text=" + login.getText());
    System.out.println("Element_Enabled=" + login.isEnabled());
    Rect rect = login.getRect();
    System.out.println("Center_X=" + rect.getCenter_x());
    System.out.println("Center_Y=" + rect.getCenter_y());
    login.touch();
}

控制台输出

Element_Id=loginButton
Element_Class=ui-btn ui-btn-up-c ui-shadow ui-btn-corner-all
Element_Query=webView css:'#loginButton' index:0
Element_Text=
Element_Enabled=false
Center_X=91.98979
Center_Y=308.5714 
com.thoughtworks.calabash.android.CalabashException: Failed to touch on: webView css:'#loginButton' index:0. (RuntimeError) No elements found. Query: webView css:'#loginButton' index:0
at com.thoughtworks.calabash.android.CalabashWrapper.touch(CalabashWrapper.java:293)
at com.thoughtworks.calabash.android.UIElement.touch(UIElement.java:196)
at com.mycompany.calabash.LoginStepDefs.user_logs_in_with_valid_credentials(LoginStepDefs.java:41)
at ?.When user "xxx@xx" logs in with valid credentials(C:/_Workspace/calabash-android-java/calabash-android-java/src/test/resources/features/login.feature:13)

更新:值得注意的是,我可以在控制台模式下使用相同的查询来触摸元素,并且设备会做出相应的响应:

irb(main):023:0> touch("webView css:'#loginButton'")
{
    "bonusInformation" => [],
             "message" => "",
             "success" => true
}

【问题讨论】:

    标签: java cucumber cucumber-jvm calabash


    【解决方案1】:

    我更新到 clabash android 0.5.1,这有助于更好地处理 webelements 上的触摸和设置文本。现在可以更好地处理 Web 视图(与 calabash android 一致)。

    https://github.com/vishnukarthikl/calabash-android-java/issues/3

    【讨论】:

      【解决方案2】:

      在通过GitHubVishnu 交谈后,我能够更改源代码以解决该错误:

      注意,必须截断附加到查询变量的字符串“index:N”,然后将其传递给 Ruby 脚本:

      CalabashWrapper.java

      public void touch(String query) throws CalabashException {
          try {
              info("Touching - %s", query);
              query = query.substring(0, query.indexOf("index:"));
              container.put(QUERY_STRING, query);
              container.runScriptlet(String.format("touch(%s)", QUERY_STRING));
              pause();
          } catch (Exception e) {
              error("Failed to touch on: %s", e, query);
              throw new CalabashException(String.format("Failed to touch on: %s. %s", query, e.getMessage()));
          }
      
      }
      

      【讨论】:

        猜你喜欢
        • 2012-12-24
        • 2019-02-14
        • 2014-05-07
        • 1970-01-01
        • 2016-03-20
        • 2018-06-08
        • 1970-01-01
        • 2018-06-28
        • 2018-12-17
        相关资源
        最近更新 更多