android - 编写 Robotium 测试以滑动打开可滑动 ListView 上的项目

标签 android listview robotium

我想与 StackOverflow 社区的其他人分享我做这件事的方式,以潜在地节省一些时间,因为我无法在任何地方找到很多相关信息。

我正在使用 SwipeListView应用程序中的插件,但它应该适用于任何其他 ListView,因为长列表项滑动。我想编写一个 Robotium 测试,将列表中包含特定文本的项目向左滑动。

最佳答案

这是一个实用程序方法,它应该进入扩展 ActivityInstrumentationTestCase2 的类中的测试函数:

protected void swipeLeftOnText(String text) {
    int fromX, toX, fromY, toY;
    int[] location = new int[2];

    View row = solo.getText(text);
    row.getLocationInWindow(location);

    // fail if the view with text cannot be located in the window
    if (location.length == 0) {
         fail("Could not find text: " + text);
    }

    fromX = location[0] + 100;
    fromY = location[1];

    toX = location[0];
    toY = fromY;

    solo.drag(fromX, toX, fromY, toY, 10);
}

关于android - 编写 Robotium 测试以滑动打开可滑动 ListView 上的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24664730/

相关文章:

Android - 从 ListView 中删除项目时的动画

android - Robotium 独奏 waitForCondition

listview - Espresso Android : Cannot scroll and click on a specific item in the list preference

Android WebView WebChromeClient : inaccurate progress value in onProgressChanged()

flutter - ListView.builder 中的 TextFields 正在消失

android ListView 滚动条样式

android - Gradle + Robotium + Jenkins

java - 向另一台设备发送通知

android - 无法在android studio中同步firebase

java - sqlite for android,如何更新表