问题
I have the following gesture recognizer in my app. I've looked at xCode7 UI and see that it has swipe up/down/left/right, but no pan or edge pan gestures.
How can one test or initiate screen edge pan gesture for UITesting purposes?
UIScreenEdgePanGestureRecognizer *leftEdgeGesture = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(show)];
leftEdgeGesture.edges = UIRectEdgeLeft;
leftEdgeGesture.delegate = self;
[self.view addGestureRecognizer:leftEdgeGesture];
回答1:
I spent a while trying to figure this out, navigating around the element hierarchy. Lots and lots of googling and finding nothing.
I gave up twice, then figured it out.
We just need two coords on the main app screen, and drag one to the other.
Works a treat!
XCUIApplication *app = [[XCUIApplication alloc] init];
[app launch];
// Set a coordinate near the left-edge, we have to use normalized coords
// so you set using percentages, 1% in on the left, 15% down from the top
XCUICoordinate *coord1 = [app coordinateWithNormalizedOffset:CGVectorMake(0.01, 0.15)];
// Then second coordinate 40 points to the right
XCUICoordinate *coord2 = [coord1 coordinateWithOffset:CGVectorMake(40, 0)];
// Perform a drag from coord1 to coord2
// Simulating swipe in from left edge
[coord1 pressForDuration:0.5f thenDragToCoordinate:coord2];
Hopefully this will help everyone else who has been struggling to simulate an edge swipe.
来源:https://stackoverflow.com/questions/34772202/xcode7-uitests-how-to-test-screen-edge-pan-gestures