如何通过 UI 测试执行 "swipe left" 操作

How can I perform a "swipe left" action via UI tests

如何通过 Xcode 中的 UI 测试执行 "swipe left" 操作来触发 segue 和更改视图控制器?

记录的代码是

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

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

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

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

Read more about swipeLeft and the accompanying gestures you can perform on elements. If you are looking for a more general "cheat sheet", I've also got you covered.

如果你不能 swipeLeft app

app.swipeLeft()

尝试在 scrollView 上调用它,比如

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

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