Skip to content

Commit

Permalink
[image_picker_ios] Update image picker UI test query for iOS 18 (#7325)
Browse files Browse the repository at this point in the history
The image picker UI changed from iOS 17 -> iOS 18 (beta), and there's an additional scrollview that wasn't present before.
Instead of selecting the first image in the first scroll view, instead select the image with the accessibility label that starts with "Photo":
```
      ��Find: First Match
        Output: {
          Image, 0x10134f070, {{-0.0, 339.7}, {142.2, 142.3}}, label: 'Photo, March 30, 2018, 12:14�PM'
        }
```
This works on previous versions of iOS as well.

Fixes flutter/flutter#150220, found in Xcode 16 beta.
  • Loading branch information
jmagman authored Aug 6, 2024
1 parent ec92d7d commit 9ce1570
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/image_picker/image_picker_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## NEXT

* Updates UI test photo element query for iOS 18.

## 0.8.12

* Re-adds Swift Package Manager compatibility.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ - (void)launchPickerAndPickWithMaxWidth:(NSNumber *)maxWidth
// Find an image and tap on it. (IOS 14 UI, images are showing directly)
XCUIElement *aImage;
if (@available(iOS 14, *)) {
aImage = [self.app.scrollViews.firstMatch.images elementBoundByIndex:1];
NSPredicate *imagePredicate = [NSPredicate predicateWithFormat:@"label BEGINSWITH 'Photo, '"];
aImage = [self.app.images matchingPredicate:imagePredicate].firstMatch;
} else {
XCUIElement *allPhotosCell = self.app.cells[@"All Photos"].firstMatch;
if (![allPhotosCell waitForExistenceWithTimeout:kElementWaitingTime]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ - (void)testSelectingFromGallery API_AVAILABLE(ios(14)) {
[self handlePermissionInterruption];

// Find an image and tap on it.
XCUIElement *aImage = [self.app.scrollViews.firstMatch.images elementBoundByIndex:1];
NSPredicate *imagePredicate = [NSPredicate predicateWithFormat:@"label BEGINSWITH 'Photo, '"];
XCUIElementQuery *imageQuery = [self.app.images matchingPredicate:imagePredicate];
XCUIElement *aImage = imageQuery.firstMatch;
os_log_error(OS_LOG_DEFAULT, "description before picking image %@", self.app.debugDescription);
if (![aImage waitForExistenceWithTimeout:kLimitedElementWaitingTime]) {
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
Expand All @@ -126,7 +128,7 @@ - (void)testSelectingFromGallery API_AVAILABLE(ios(14)) {
[doneButton tap];

// Find an image and tap on it to have access to selected photos.
aImage = [self.app.scrollViews.firstMatch.images elementBoundByIndex:1];
aImage = imageQuery.firstMatch;

os_log_error(OS_LOG_DEFAULT, "description before picking image %@", self.app.debugDescription);
if (![aImage waitForExistenceWithTimeout:kLimitedElementWaitingTime]) {
Expand Down

0 comments on commit 9ce1570

Please sign in to comment.