Fix testAppExtensionLaunching for Xcode 15/iOS 17 (flutter/engine#49242)

Fixes https://github.com/flutter/flutter/issues/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
This commit is contained in:
Victoria Ashworth
2023-12-20 10:58:19 -06:00
committed by GitHub
parent 07c8907f45
commit 75cf8ed82c

View File

@@ -19,6 +19,11 @@
}
- (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,15 +32,27 @@
}
[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));
}
// 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"];