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



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

记录的代码是

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

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

很难确切地说出您要滑动哪个视图。以下代码将在标题为"滑动我"的标签上执行"向左轻扫"手势。一旦你定位了你的视图,应该很容易遵循相同的技术。

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

详细了解swipeLeft以及您可以对元素执行的随附手势。如果您正在寻找更通用的"备忘单",我也为您提供了保障。

如果你不能swipeLeft app

app.swipeLeft()

尝试在scrollView上调用它,例如

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

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

最新更新