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

Commit 14a3fa6

Browse files
authored
Fix testAppExtensionLaunching for Xcode 15/iOS 17 (#49242)
Fixes flutter/flutter#140181. Example of fix working on macOS 13 with Xcode 15 and iOS 17 simulator: https://ci.chromium.org/ui/p/flutter/builders/try/Mac%20Engine%20Drone/586366/overview [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 3e12837 commit 14a3fa6

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

testing/scenario_app/ios/Scenarios/ScenariosUITests/AppExtensionTests.m

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)