Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 323
FrozenHeart Avatar asked Dec 15 '22 08:12

FrozenHeart


1 Answers

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.

like image 146
Joe Masilotti Avatar answered Dec 16 '22 21:12

Joe Masilotti