Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Fix testAppExtensionLaunching for Xcode 15/iOS 17 #49242

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand All @@ -27,15 +32,27 @@ - (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.
for (int i = 0; i < self.hostApplication.collectionViews.cells.count; i++) {
XCUIElement* shareSheetCell =
[self.hostApplication.collectionViews.cells elementBoundByIndex:i];
if (![shareSheetCell.label isEqualToString:@"XCElementSnapshotPrivilegedValuePlaceholder"]) {
continue;
}

// 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));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Xcode 15/iOS 17, sometimes it would process self.hostApplication.collectionViews.cells.count below before the sheet appeared and therefore would be 0. So I added this to wait for it to populate.


// 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.
NSPredicate* cellPredicate = [NSPredicate
predicateWithFormat:
@"label == 'XCElementSnapshotPrivilegedValuePlaceholder' OR label = 'Scenarios'"];
NSArray<XCUIElement*>* shareSheetCells =
[self.hostApplication.collectionViews.cells matchingPredicate:cellPredicate]
.allElementsBoundByIndex;
for (XCUIElement* shareSheetCell in shareSheetCells) {
[shareSheetCell tap];

XCUIElement* flutterView = self.hostApplication.otherElements[@"flutter_view"];
Expand Down