[platform_view]delete previously installed app if needed (#110201)
This commit is contained in:
parent
605661c994
commit
5217f89dcf
@ -26,29 +26,34 @@ static const CGFloat kStandardTimeOut = 60.0;
|
|||||||
[super setUp];
|
[super setUp];
|
||||||
self.continueAfterFailure = NO;
|
self.continueAfterFailure = NO;
|
||||||
|
|
||||||
// Retry launching the app if it fails to launch.
|
// Delete the previously installed app if needed before running.
|
||||||
// This is trying to fix a "failed to terminate" failure, which is likely a bug in Xcode.
|
// This is to address "Failed to terminate" failure.
|
||||||
// The solution is based on https://stackoverflow.com/questions/41872848/xctests-failing-to-launch-app-in-simulator-intermittently
|
// The solution is based on https://stackoverflow.com/questions/50016018/uitest-failed-to-terminate-com-test-abc3708-after-60-0s-state-is-still-runnin
|
||||||
int remainingLaunchCount = 10;
|
XCUIApplication *springboard = [[XCUIApplication alloc] initWithBundleIdentifier:@"com.apple.springboard"];
|
||||||
while (true) {
|
[springboard activate];
|
||||||
|
XCUIElement *appIcon = springboard.icons[@"ios_platform_view_tests"];
|
||||||
|
|
||||||
|
if ([appIcon waitForExistenceWithTimeout:kStandardTimeOut]) {
|
||||||
|
NSLog(@"Deleting previously installed app.");
|
||||||
|
|
||||||
|
// Make icons wiggle
|
||||||
|
[appIcon pressForDuration:3];
|
||||||
|
|
||||||
|
// Tap the "x" button
|
||||||
|
[appIcon.buttons[@"DeleteButton"] tap];
|
||||||
|
// Tap the delete confirmation
|
||||||
|
[springboard.alerts.buttons[@"Delete App"] tap];
|
||||||
|
// Tap the second delete confirmation
|
||||||
|
[springboard.alerts.buttons[@"Delete"] tap];
|
||||||
|
// Press home button to stop wiggling
|
||||||
|
[XCUIDevice.sharedDevice pressButton:XCUIDeviceButtonHome];
|
||||||
|
[NSThread sleepForTimeInterval:3];
|
||||||
|
} else {
|
||||||
|
NSLog(@"No previously installed app found.");
|
||||||
|
}
|
||||||
|
|
||||||
self.app = [[XCUIApplication alloc] init];
|
self.app = [[XCUIApplication alloc] init];
|
||||||
[self.app launch];
|
[self.app launch];
|
||||||
remainingLaunchCount -= 1;
|
|
||||||
[NSThread sleepForTimeInterval:3];
|
|
||||||
if (self.app.exists) {
|
|
||||||
// success launch
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (remainingLaunchCount > 0) {
|
|
||||||
NSLog(@"Retry launch with remaining launch count %d", remainingLaunchCount);
|
|
||||||
[self.app terminate];
|
|
||||||
[NSThread sleepForTimeInterval:3];
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSLog(@"Failed to launch");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)tearDown {
|
- (void)tearDown {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user