使用UI测试滚动单元格

sau*_*123 5 scroll uitableview ios xctest

有没有像这样的方法

- (void)scrollByDeltaX:(CGFloat)deltaX deltaY:(CGFloat)deltaY;
Run Code Online (Sandbox Code Playgroud)

对于iOS?

我认为上述方法仅适用于OSX.我想根据提供的deltaval滚动我的tableview.

提前致谢.

Ole*_*tha 6

在iOS上,XCUIElement.press(forDuration:thenDragTo:)如果要移动元素,则可以使用.

要在相对坐标方面移动,您可以获取XCUICoordinate元素,然后使用XCUICoordinate.press(forDuration:thenDragTo:).

let table = XCUIApplication().tables.element(boundBy:0)

// Get the coordinate for the bottom of the table view
let tableBottom = table.coordinate(withNormalizedOffset:CGVector(dx: 0.5, dy: 1.0))

// Scroll from tableBottom to new coordinate
let scrollVector = CGVector(dx: 0.0, dy: -30.0) // Use whatever vector you like
tableBottom.press(forDuration: 0.5, thenDragTo: tableBottom.withOffset(scrollVector))
Run Code Online (Sandbox Code Playgroud)

或者在Objective-C中:

XCUIApplication *app = [[XCUIApplication alloc] init];
XCUIElement *table = [app.tables elementBoundByIndex: 0];

// Get the coordinate for the bottom of the table view
XCUICoordinate *tableBottom = [table coordinateWithNormalizedOffset:CGVectorMake(0.5, 1.0)];

// Scroll from tableBottom to new coordinate
CGVector scrollVector = CGVectorMake(0.0, -30.0); // Use whatever vector you like
[tableBottom pressForDuration:0.5 thenDragToCoordinate:[tableBottom coordinateWithOffset:scrollVector]];
Run Code Online (Sandbox Code Playgroud)


Wad*_*ade 5

Oletha的答案正是我所寻找的,但Objective-C例子中有一些小错误.由于编辑被拒绝,我会在此处将其作为对其他任何人的回复:

XCUIApplication *app = [[XCUIApplication alloc] init];
XCUIElement *table = [app.tables elementBoundByIndex: 0];

// Get the coordinate for the bottom of the table view
XCUICoordinate *tableBottom = [table 
coordinateWithNormalizedOffset:CGVectorMake( 0.5, 1.0)];

// Scroll from tableBottom to new coordinate
CGVector scrollVector = CGVectorMake( 0.0, -30.0); // Use whatever vector you like
[tableBottom pressForDuration:0.5 thenDragToCoordinate:[tableBottom coordinateWithOffset:scrollVector]];
Run Code Online (Sandbox Code Playgroud)