【发布时间】:2018-01-24 09:24:17
【问题描述】:
在我的UITableView 之一中有超过 10 行。我想在UITestCase 运行时滚动到最后一行。
我已经写了下面的代码来滚动到最后一行。
-(void)scrollToElement:(XCUIElement *)element application:(XCUIApplication *)app{
while ([self visible:element withApplication:app]) {
XCUIElement *searchResultTableView = app.tables[@"searchResultView"];
XCUICoordinate *startCoord = [searchResultTableView coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.5)];
XCUICoordinate *endCoord = [startCoord coordinateWithOffset:CGVectorMake(0.0, -262)];
[startCoord pressForDuration:0.01 thenDragToCoordinate:endCoord];
}
}
-(BOOL)visible:(XCUIElement *)element withApplication:(XCUIApplication *)app{
if (element.exists && !CGRectIsEmpty(element.frame) && element.isHittable) {
return CGRectContainsRect([app.windows elementBoundByIndex:0].frame, element.frame);
} else {
return FALSE;
}
}
我通过下面的代码在我的UITestCase 方法中调用了上述方法
XCUIElement *searchResultTableView = app.tables[@"searchResultView"];
[self waitForElementToAppear:searchResultTableView withTimeout:30];
XCUIElement *table = [app.tables elementBoundByIndex:0];
XCUIElement *lastCell = [table.cells elementBoundByIndex:table.cells.count - 1];
[self scrollToElement:lastCell application:app];
通过此代码,我可以滚动到最后一行,但到达最后一行后,它继续滚动意味着无法停止滚动。
请帮我滚动到最后一行,然后它应该停止滚动,以便我可以执行下一个动作事件。
我参考了StackOverFlow 的答案,但没有一个符合我的要求。
提前致谢。
【问题讨论】:
-
visible的实现只返回element.exists && element.isHittable的结果就足够了...对你有用吗? -
感谢@Oletha 的重播。我已经尝试过 element.exists && element.isHittable,但仍然无法正常工作。
标签: ios xcode-ui-testing xcuitest