简体   繁体   中英

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

How can I perform a "swipe left" action to trigger a segue and change view controller via UI tests in Xcode?

The recorded code is

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

but it seems that it doesn't work -- as far as I see, view controller doesn't change to the new one.

It is hard to tell exactly which view you are trying to swipe. The following code will perform the "swipe left" gesture on a label titled "Swipe Me". Once you target your view it should be easy to follow the same technique.

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 .

If you can't swipeLeft on app

app.swipeLeft()

try calling it on the scrollView , like

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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