[platform_view]add timeout for alert buttons and a few other changes to fix a test flake (#110516)

This commit is contained in:
hellohuanlin 2022-08-29 17:59:58 -07:00 committed by GitHub
parent 99372ba1e4
commit ee98003e24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,17 +36,30 @@ static const CGFloat kStandardTimeOut = 60.0;
if ([appIcon waitForExistenceWithTimeout:kStandardTimeOut]) { if ([appIcon waitForExistenceWithTimeout:kStandardTimeOut]) {
NSLog(@"Deleting previously installed app."); NSLog(@"Deleting previously installed app.");
// Make icons wiggle // It's possible that app icon is not hittable yet.
[appIcon pressForDuration:3]; NSPredicate *hittable = [NSPredicate predicateWithFormat:@"exists == YES AND hittable == YES"];
[self expectationForPredicate:hittable evaluatedWithObject:appIcon handler:nil];
[self waitForExpectationsWithTimeout:kStandardTimeOut handler:nil];
// Pressing for 2 seconds will bring up context menu.
// Pressing for 3 seconds will dismiss the context menu and make icons wiggle.
[appIcon pressForDuration:2];
// The "Remove App" button in context menu.
XCUIElement *contextMenuRemoveButton = springboard.buttons[@"Remove App"];
XCTAssert([contextMenuRemoveButton waitForExistenceWithTimeout:kStandardTimeOut], @"The context menu remove app button must appear.");
[contextMenuRemoveButton tap];
// Tap the "x" button
[appIcon.buttons[@"DeleteButton"] tap];
// Tap the delete confirmation // Tap the delete confirmation
[springboard.alerts.buttons[@"Delete App"] tap]; XCUIElement *deleteConfirmationButton = springboard.alerts.buttons[@"Delete App"];
XCTAssert([deleteConfirmationButton waitForExistenceWithTimeout:kStandardTimeOut], @"The first delete confirmation button must appear.");
[deleteConfirmationButton tap];
// Tap the second delete confirmation // Tap the second delete confirmation
[springboard.alerts.buttons[@"Delete"] tap]; XCUIElement *secondDeleteConfirmationButton = springboard.alerts.buttons[@"Delete"];
// Press home button to stop wiggling XCTAssert([secondDeleteConfirmationButton waitForExistenceWithTimeout:kStandardTimeOut], @"The second delete confirmation button must appear.");
[XCUIDevice.sharedDevice pressButton:XCUIDeviceButtonHome]; [secondDeleteConfirmationButton tap];
[NSThread sleepForTimeInterval:3]; [NSThread sleepForTimeInterval:3];
} else { } else {
NSLog(@"No previously installed app found."); NSLog(@"No previously installed app found.");