【问题标题】:Robotium cannot getText(string) from textviews that are not visible from very top or very bottom of scrollViewRobotium 无法从滚动视图的最顶部或最底部不可见的文本视图中获取文本(字符串)
【发布时间】:2013-05-28 18:59:05
【问题描述】:

Robotium 4.1 似乎没有任何滚动到某个点然后停止的功能(适用于 ScrollView 而不是 ListView 对象)。我的问题是我需要从 TextView 对象接收文本,该对象从 scrollView 的最顶部不可见,但从底部也不可见。 ScrollView 对象和 TextView 对象在目标包的 GUI 类中都是私有的,因此不能直接接收字符串。

这是我的尝试

    solo.waitForText("Start Logging");
    solo.clickOnText("Start Logging");
    solo.waitForText("Performing Throughput Test");

    assertEquals(
            GUIHelperFunctions.isServiceRunning(GlobalVariables.getContext(),
                    GlobalVariables.getSERVICENAME(), true), true);
    boolean inProgress = true;
    while (inProgress == true){
        if(!solo.searchText("Performing Throughput Test",true)){
            inProgress = false;
        }
    }


    String message = solo.getText("Upload Throughput:").getText().toString();

我发现当你将最后一行换成时它也失败了

    assertTrue(solo.searchText("Upload Throughput:"));

在我的项目中,我收到了其他几个 TextView 的内容,它们也在 LinearLayout 中,它是 ScrollView 的直接子项,但所有这些都可以从最顶部或最底部看到。

有没有人找到解决此问题的方法或在某个位置停止滚动 ScrollView 的方法?

【问题讨论】:

    标签: android android-layout android-view robotium android-scrollview


    【解决方案1】:

    尝试使用:

    assertTrue(solo.waitForText("Upload Throughput:", 1, 20000, true));
    

    之前

    String message = solo.getText("Upload Throughput:").getText().toString();
    

    【讨论】:

    • 感谢 maszter,当我插入 solo.scrollToTop(); 时,您的方法奏效了;在你提出建议之前。显然,在搜索元素时,robotium 4.1 很高兴在搜索时自行向下滚动,但不向上滚动。无论出于何种原因,似乎仍然有必要在此基础上使用您建议的断言,但不确定原因。
    • solo.waitForText 返回布尔值,它在文本可见时返回 true。如果没有断言,当视图不会出现时,你会在下一行得到 NPE,这是出乎意料的。使用断言,您希望该视图可能不会出现,并且您可以获得更易读的信息,尤其是如果您为断言添加文本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多