如何通过Xcode中的UI测试执行“向左滑动”操作以触发segue并更改视图控制器?
录制的代码是
[[[[[[[XCUIApplication alloc] init].otherElements containingType:XCUIElementTypeNavigationBar identifier:@"UIView"] childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element tap];
但似乎它不起作用 - 据我所知,视图控制器不会更改为新的。
很难准确判断您要尝试滑动的视图。以下代码将在标题为“Swipe Me”的标签上执行“向左滑动”手势。定位视图后,应该很容易遵循相同的技术。
XCUIApplication *app = [XCUIApplication alloc] init];
[app.labels[@"Swipe Me"] swipeLeft];
Read more about swipeLeft
以及您可以对元素执行的伴随手势。如果你正在寻找一个更通用的“备忘单”,我也是got you covered。
如果你不能在swipeLeft
上app
app.swipeLeft()
尝试在scrollView
上调用它,就像
app.scrollViews.element(boundBy: 0).swipeLeft()
无需知道UI堆栈上当前可用的UI元素,这对我有用:
app.windows.element(boundBy:0).swipeLeft()