写Robotium测试刷卡上滑动式的ListView打开项目 [英] Writing a Robotium test to swipe open an item on a swipeable ListView

查看:171
本文介绍了写Robotium测试刷卡上滑动式的ListView打开项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想和大家分享我的计算器社会其他成员所采取的方式,潜在的节约一些时间,因为我无法找到任何地方很多相关的信息。

I would like to share the way i did it with the rest of the StackOverflow community, to potentially save someone some time as i was unable to find much relevant info anywhere.

我在应用程序中使用 SwipeListView 的插件,但它应该对任何其他工作的ListView只要列表项轻扫。我想写一个Robotium测试将包含特定文本左边的列表上刷卡的项目。

I am using a SwipeListView plugin in the app, but it should work for any other ListView as long list items swipe. I wanted to write a Robotium test that will swipe an item on the list containing specific text to the left.

推荐答案

下面是一个应该进入测试功能,在扩展ActivityInstrumentationTestCase2类实用方法:

Here is a utility method that should go into a test function in a class that extends 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);
}

这篇关于写Robotium测试刷卡上滑动式的ListView打开项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆