如何通过UI测试执行“向左滑动”操作

问题描述 投票:4回答:3

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

录制的代码是

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

但似乎它不起作用 - 据我所知,视图控制器不会更改为新的。

ios objective-c xcode xcode7 xcode-ui-testing
3个回答
10
投票

很难准确判断您要尝试滑动的视图。以下代码将在标题为“Swipe Me”的标签上执行“向左滑动”手势。定位视图后,应该很容易遵循相同的技术。

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

Read more about swipeLeft以及您可以对元素执行的伴随手势。如果你正在寻找一个更通用的“备忘单”,我也是got you covered


1
投票

如果你不能在swipeLeftapp

app.swipeLeft()

尝试在scrollView上调用它,就像

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

0
投票

无需知道UI堆栈上当前可用的UI元素,这对我有用: app.windows.element(boundBy:0).swipeLeft()

© www.soinside.com 2019 - 2024. All rights reserved.