有没有办法通过 iOS 13 的 XCUI 测试在 iPad 上自动执行多任务处理?
显然,以下代码在 2017 年有效(https://forums.developer.apple.com/thread/38973)。但是,它不适用于 iOS 13(未尝试过 iOS 12)。我尝试过使用不同的滑动坐标,但没有任何效果。
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
XCUIApplication *app = [[XCUIApplication alloc] init];
[app launch];
[XCUIDevice sharedDevice].orientation = UIDeviceOrientationLandscapeLeft;
if ([[app coordinateWithNormalizedOffset:CGVectorMake(1.0, 1.0)] screenPoint].x < [[app coordinateWithNormalizedOffset:CGVectorMake(1.0, 1.0)] screenPoint].y)
{ //if multitasking is not enabled yet
////make the app switcher menu appear
XCUICoordinate *coord1 = [app coordinateWithNormalizedOffset:CGVectorMake(0.5, 1.0)];
XCUICoordinate *coord2 = [coord1 coordinateWithOffset:CGVectorMake(0, -200)];
// Perform a drag from coord1 to coord2
[coord1 pressForDuration:0.5f thenDragToCoordinate:coord2];
////open an another app
XCUICoordinate *otherAppIconCoordinate = [app coordinateWithNormalizedOffset:CGVectorMake(1.2, 0.9)];
[otherAppIconCoordinate tap];
//switch from slide-over to split-view mode (drag the slide-over dragging thingy just a little bit to the left)
coord1 = [app coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.73)];
coord2 = [coord1 coordinateWithOffset:CGVectorMake(0, -50)];
[coord1 pressForDuration:0.5f thenDragToCoordinate:coord2];
} else
{ //if multitasking is already enabled
////make the split-view disappear
XCUICoordinate *coord1 = [app coordinateWithNormalizedOffset:CGVectorMake(0.5, 1.0)];
XCUICoordinate *coord2 = [coord1 coordinateWithOffset:CGVectorMake(0, [[app coordinateWithNormalizedOffset:CGVectorMake(1.0, 1.0)] screenPoint].x)];
// Perform a drag from coord1 to coord2
[coord1 pressForDuration:0.5f thenDragToCoordinate:coord2];
}
//give us a bit time so we can enjoy the app in split-view mode (feel free to delete this line... :) )
sleep(10);
}