滑动SeekBar并在Android的UiAutomation上停止

滑动SeekBar并在Android的UiAutomation上停止,android,scroll,seekbar,android-uiautomator,Android,Scroll,Seekbar,Android Uiautomator,我正在通过UiAutomatorTestCase类为android设计一个自动化。 我想在UIAutomator上控制SeekBar滑动和TestView 例如,如果SeekBar向左移动。文本视图更改为负数。如果数字是“40”。我想停止刷卡 我可以向左滑动搜索杆,但无法阻止它 UiScrollable seekbar = new UiScrollable(new UiSelector().resourceId("com.test:id/setting_item_child_menu_seekb

我正在通过UiAutomatorTestCase类为android设计一个自动化。 我想在UIAutomator上控制SeekBar滑动和TestView

例如,如果SeekBar向左移动。文本视图更改为负数。如果数字是“40”。我想停止刷卡

我可以向左滑动搜索杆,但无法阻止它

UiScrollable seekbar = new UiScrollable(new UiSelector().resourceId("com.test:id/setting_item_child_menu_seekbar"));
seekbar.swipeLeft(200);

请帮助我,当TextView的某些测试为“40”时,如何停止SeekBar。

我找到了控制SeekBar的替代方法,因为我还发现由于一些问题,标准方法很难使用,因此它是:

private void clickSeekbar (float position) {
    while ((seekBarUiObj2 = mDevice.findObject(By.res(BASIC_SAMPLE_PACKAGE+":id/seekbar"))) == null) {
        mDevice.click(200,200);
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    Rect rect = seekBarUiObj2.getVisibleBounds();
    mDevice.click(rect.left+5/*pixels*/+(int)((rect.right-rect.left-10/*pixels*/)*position), ((rect.top+rect.bottom)/2));

}   
诀窍是点击seekbar上所需位置的设备。 它起作用了。 whlle循环确保seekbar在屏幕上,如果不点击屏幕上的某个位置,这将使seekbar出现。 然后根据所需位置计算要单击的位置。
只有当你的seekbar非常薄,比如1或2像素时,它才可能不起作用。

为什么要测试40这样的数字?测试绝对最高值和最低值不是更容易吗?i、 e.0和100?通过这种方式,您可以保证将搜索杆一直滑动到任意一端将有一个可靠的数字进行检查。浮动位置参数的起始值应为0f,结束值应为1f,中间值应为0.5f。