是否可以通过Espresso执行拖放操作?我需要向下移动一个视图(直线),以便在我的自动化测试中接受一些条件。
发布于 2016-02-11 05:38:23
您可以使用GeneralSwipeAction执行拖放操作。
public static ViewAction swipeUp() {
return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.BOTTOM_CENTER,
GeneralLocation.TOP_CENTER, Press.FINGER);
}您也可以自定义位置以满足您的要求。
发布于 2016-02-22 09:07:22
我就是这么做的。你有更多的机会去了解你的观点应该发生的事情。但接受答案也要执行拖放。
public static void drag(Instrumentation inst, float fromX, float toX, float fromY,
float toY, int stepCount) {
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis();
float y = fromY;
float x = fromX;
float yStep = (toY - fromY) / stepCount;
float xStep = (toX - fromX) / stepCount;
MotionEvent event = MotionEvent.obtain(downTime, eventTime,
MotionEvent.ACTION_DOWN, x, y, 0);
inst.sendPointerSync(event);
for (int i = 0; i < stepCount; ++i) {
y += yStep;
x += xStep;
eventTime = SystemClock.uptimeMillis();
event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, x, y, 0);
inst.sendPointerSync(event);
}
eventTime = SystemClock.uptimeMillis();
event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, x, y, 0);
inst.sendPointerSync(event);
inst.waitForIdleSync();
}https://stackoverflow.com/questions/35297442
复制相似问题