繁体   English   中英

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

[英]How can I perform a “swipe left” action via UI tests

如何通过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];

阅读有关swipeLeft以及您可以对元素执行的伴随手势的更多信息 如果您正在寻找更通用的“备忘单”,我也能为您提供帮助

如果你不能在app swipeLeft

app.swipeLeft()

尝试在scrollView上调用它,就像

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM