2016-02-27 67 views
3

如何执行“向左滑动”操作以通过Xcode中的UI测试触发Segue并更改视图控制器?如何通过UI测试执行“向左滑动”操作

记录的代码是

[[[[[[[XCUIApplication alloc] init].otherElements containingType:XCUIElementTypeNavigationBar identifier:@"UIView"] childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element tap]; 

但似乎这是行不通的 - 据我看到的,视图控制器不会更改为新的。

回答

8

很难确切地说出您想要扫描的视图。以下代码将在标题为“轻扫我”的标签上执行“向左滑动”手势。一旦你瞄准你的观点,应该很容易遵循相同的技术。

XCUIApplication *app = [XCUIApplication alloc] init]; 
[app.labels[@"Swipe Me"] swipeLeft]; 

Read more about swipeLeft以及您可以在元素上执行的伴随手势。如果你正在寻找一个更一般的“作弊表”,我也got you covered

+0

是的,它的工作原理,非常感谢。为什么我的测试应用程序几次顺便运行?我只有stub方法'setUp'和'tearDown'和**一个** UI测试,下面的代码 - 'XCUIApplication * app = [[XCUIApplication alloc] init]; [app.images [@“swipeleft”] swipeLeft]; XCUIElement * element = app.buttons [@“icon share”]; [self waitForElementToAppear:element withTimeout:5];' – FrozenHeart

+1

@Joe Masilotti我可以更轻松地处理滑动左手势吗?例如向左滑动距离? –

+0

@RyanChou你可以下载到'XCUICoordinate' API并从一个元素拖到另一个元素。查看[这个拉到更新的例子](http://masilotti.com/ui-testing-cheat-sheet/#how-to-quot-pull-to-refresh-quot)。 –

0

如果不能swipeLeftapp

app.swipeLeft() 

尝试调用它的scrollView,像

app.scrollViews.element(boundBy: 0).swipeLeft() 
0

,而不需要知道什么UI元素是目前可用的UI栈上,这已经为我工作: app.windows.element(boundBy:0).swipeLeft()

相关问题