From b9f7d5eb3945f8e191180757a5199570ffc23274 Mon Sep 17 00:00:00 2001 From: Victoria Ashworth Date: Tue, 19 Dec 2023 11:38:01 -0600 Subject: [PATCH 1/2] Fix testAppExtensionLaunching for Xcode 15 --- .../ScenariosUITests/AppExtensionTests.m | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/testing/scenario_app/ios/Scenarios/ScenariosUITests/AppExtensionTests.m b/testing/scenario_app/ios/Scenarios/ScenariosUITests/AppExtensionTests.m index 70d4e0a190a3b..9433b6bb833db 100644 --- a/testing/scenario_app/ios/Scenarios/ScenariosUITests/AppExtensionTests.m +++ b/testing/scenario_app/ios/Scenarios/ScenariosUITests/AppExtensionTests.m @@ -19,6 +19,11 @@ - (void)setUp { } - (void)testAppExtensionLaunching { + // Launch the Scenarios app first to ensure it's installed then close it. + XCUIApplication* app = [[XCUIApplication alloc] init]; + [app launch]; + [app terminate]; + [self.hostApplication launch]; XCUIElement* button = self.hostApplication.buttons[@"Open Share"]; if (![button waitForExistenceWithTimeout:10]) { @@ -27,13 +32,25 @@ - (void)testAppExtensionLaunching { } [button tap]; BOOL launchedExtensionInFlutter = NO; - // Custom share extension button (like the one in this test) does not have a unique - // identity. They are all identified as `XCElementSnapshotPrivilegedValuePlaceholder`. - // Loop through all the `XCElementSnapshotPrivilegedValuePlaceholder` and find the Flutter one. + + // Wait for first cell of share sheet to appear. + XCUIElement* firstCell = self.hostApplication.collectionViews.cells.firstMatch; + if (![firstCell waitForExistenceWithTimeout:10]) { + NSLog(@"%@", self.hostApplication.debugDescription); + XCTFail(@"Failed due to not able to find any cells with %@ seconds", @(10)); + } + + // Custom share extension button (like the one in this test) does not have a + // unique identity on older versions of iOS. They are all identified as + // `XCElementSnapshotPrivilegedValuePlaceholder`. On iOS 17, they are + // identified by name. Loop through all the buttons labeled + // `XCElementSnapshotPrivilegedValuePlaceholder` or `Scenarios` to find the + // Flutter one. for (int i = 0; i < self.hostApplication.collectionViews.cells.count; i++) { XCUIElement* shareSheetCell = [self.hostApplication.collectionViews.cells elementBoundByIndex:i]; - if (![shareSheetCell.label isEqualToString:@"XCElementSnapshotPrivilegedValuePlaceholder"]) { + if (![shareSheetCell.label isEqualToString:@"XCElementSnapshotPrivilegedValuePlaceholder"] && + ![shareSheetCell.label isEqualToString:@"Scenarios"]) { continue; } [shareSheetCell tap]; From 23a7ae1e0aa2c1265ae7b7a645bf5e9f1b2f659e Mon Sep 17 00:00:00 2001 From: Victoria Ashworth Date: Tue, 19 Dec 2023 15:38:49 -0600 Subject: [PATCH 2/2] Change way of filtering cells for testAppExtensionLaunching --- .../Scenarios/ScenariosUITests/AppExtensionTests.m | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/testing/scenario_app/ios/Scenarios/ScenariosUITests/AppExtensionTests.m b/testing/scenario_app/ios/Scenarios/ScenariosUITests/AppExtensionTests.m index 9433b6bb833db..32555de44ef81 100644 --- a/testing/scenario_app/ios/Scenarios/ScenariosUITests/AppExtensionTests.m +++ b/testing/scenario_app/ios/Scenarios/ScenariosUITests/AppExtensionTests.m @@ -46,13 +46,13 @@ - (void)testAppExtensionLaunching { // identified by name. Loop through all the buttons labeled // `XCElementSnapshotPrivilegedValuePlaceholder` or `Scenarios` to find the // Flutter one. - for (int i = 0; i < self.hostApplication.collectionViews.cells.count; i++) { - XCUIElement* shareSheetCell = - [self.hostApplication.collectionViews.cells elementBoundByIndex:i]; - if (![shareSheetCell.label isEqualToString:@"XCElementSnapshotPrivilegedValuePlaceholder"] && - ![shareSheetCell.label isEqualToString:@"Scenarios"]) { - continue; - } + NSPredicate* cellPredicate = [NSPredicate + predicateWithFormat: + @"label == 'XCElementSnapshotPrivilegedValuePlaceholder' OR label = 'Scenarios'"]; + NSArray* shareSheetCells = + [self.hostApplication.collectionViews.cells matchingPredicate:cellPredicate] + .allElementsBoundByIndex; + for (XCUIElement* shareSheetCell in shareSheetCells) { [shareSheetCell tap]; XCUIElement* flutterView = self.hostApplication.otherElements[@"flutter_view"];