是否可以在iOS UI测试中模拟两指滑动?

时间:2019-05-13 10:58:29

标签: ios swift swipe gesture xcuitest

我想在我的UI测试中执行两指滑动。我正在使用XCUITest框架。我尝试了所有的捏合和旋转方法,但似乎对此功能没有内置支持。

1 个答案:

答案 0 :(得分:0)

我不知道它是否可以工作,但是您可以尝试模拟两个不同的手指同时拖动屏幕。像这样:

XCUIApplication *app = [[XCUIApplication alloc] init];
[app launch];

// Set a coordinate near the left-edge, we have to use normalized coords
// so you set using percentages, 1% in on the left, 15% down from the top
XCUICoordinate *coord1 = [app coordinateWithNormalizedOffset:CGVectorMake(0.01, 0.15)];

// Then second coordinate 40 points to the right
XCUICoordinate *coord2 = [coord1 coordinateWithOffset:CGVectorMake(40, 0)];

// Third coordinate 100 points down from the first
XCUICoordinate *coord3 = [coord1 coordinateWithOffset:CGVectorMake(0, 100)];

// Last one is 100 points down from the second
XCUICoordinate *coord4 = [coord2 coordinateWithOffset:CGVectorMake(0, 100)];

// Perform a drag from coord1 to coord3
[coord1 pressForDuration:0.5f thenDragToCoordinate:coord3];
// Perform a drag from coord2 to coord4
[coord2 pressForDuration:0.5f thenDragToCoordinate:coord4];