@@ -19,6 +19,11 @@ - (void)setUp {
1919}
2020
2121- (void )testAppExtensionLaunching {
22+ // Launch the Scenarios app first to ensure it's installed then close it.
23+ XCUIApplication* app = [[XCUIApplication alloc ] init ];
24+ [app launch ];
25+ [app terminate ];
26+
2227 [self .hostApplication launch ];
2328 XCUIElement* button = self.hostApplication .buttons [@" Open Share" ];
2429 if (![button waitForExistenceWithTimeout: 10 ]) {
@@ -27,15 +32,27 @@ - (void)testAppExtensionLaunching {
2732 }
2833 [button tap ];
2934 BOOL launchedExtensionInFlutter = NO ;
30- // Custom share extension button (like the one in this test) does not have a unique
31- // identity. They are all identified as `XCElementSnapshotPrivilegedValuePlaceholder`.
32- // Loop through all the `XCElementSnapshotPrivilegedValuePlaceholder` and find the Flutter one.
33- for (int i = 0 ; i < self.hostApplication .collectionViews .cells .count ; i++) {
34- XCUIElement* shareSheetCell =
35- [self .hostApplication.collectionViews.cells elementBoundByIndex: i];
36- if (![shareSheetCell.label isEqualToString: @" XCElementSnapshotPrivilegedValuePlaceholder" ]) {
37- continue ;
38- }
35+
36+ // Wait for first cell of share sheet to appear.
37+ XCUIElement* firstCell = self.hostApplication .collectionViews .cells .firstMatch ;
38+ if (![firstCell waitForExistenceWithTimeout: 10 ]) {
39+ NSLog (@" %@ " , self.hostApplication .debugDescription );
40+ XCTFail (@" Failed due to not able to find any cells with %@ seconds" , @(10 ));
41+ }
42+
43+ // Custom share extension button (like the one in this test) does not have a
44+ // unique identity on older versions of iOS. They are all identified as
45+ // `XCElementSnapshotPrivilegedValuePlaceholder`. On iOS 17, they are
46+ // identified by name. Loop through all the buttons labeled
47+ // `XCElementSnapshotPrivilegedValuePlaceholder` or `Scenarios` to find the
48+ // Flutter one.
49+ NSPredicate * cellPredicate = [NSPredicate
50+ predicateWithFormat:
51+ @" label == 'XCElementSnapshotPrivilegedValuePlaceholder' OR label = 'Scenarios'" ];
52+ NSArray <XCUIElement*>* shareSheetCells =
53+ [self .hostApplication.collectionViews.cells matchingPredicate: cellPredicate]
54+ .allElementsBoundByIndex ;
55+ for (XCUIElement* shareSheetCell in shareSheetCells) {
3956 [shareSheetCell tap ];
4057
4158 XCUIElement* flutterView = self.hostApplication .otherElements [@" flutter_view" ];
0 commit comments