-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[image_picker] Image picker phpicker impl #3835
Changes from 16 commits
9496772
a4f8416
e8c128c
0305c42
55cd773
1516e73
5b64833
36b6a2a
1d2679a
6566bf0
a4d2a12
9ed3fcf
7f81b7b
62bfcfd
97311f9
cc7c5b1
04a8452
b930c97
9d4c04d
0728176
852a828
13e5e9d
aa8a878
f14c616
7710140
29e5dfd
a83440f
97f24f8
6b295e0
f1ae1f2
30d9597
89a6433
f3f84b4
6e41e86
55252bf
4785b7c
202699c
aab9714
c04a4dd
615e5a6
362bede
4d753d3
049c365
0812f61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,7 +165,7 @@ - (void)launchPickerAndPick { | |
// 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.firstMatch; | ||
aImage = [self.app.scrollViews.firstMatch.images elementBoundByIndex:1]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to select the 2nd element instead of 2? Is this a critical change or just that you think testing the 2nd image is better? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is because there is a known issue to pick HEIC images with PHPicker implementation. But only for simulators. So we have two options here. Either test with real device or test with non-HEIC images until Apple solves the issue. |
||
} else { | ||
XCUIElement* allPhotosCell = [self.app.cells | ||
elementMatchingPredicate:[NSPredicate predicateWithFormat:@"label == %@", @"All Photos"]]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
// | ||
// ImagePickerFromLimitedGalleryUITests.m | ||
// RunnerUITests | ||
// | ||
// Created by Yusuf Dag on 28/04/2021. | ||
// Copyright © 2021 The Flutter Authors. All rights reserved. | ||
// | ||
cyanglaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#import <XCTest/XCTest.h> | ||
#import <os/log.h> | ||
|
||
const int kLimitedElementWaitingTime = 30; | ||
|
||
@interface ImagePickerFromLimitedGalleryUITests : XCTestCase | ||
|
||
@property(nonatomic, strong) XCUIApplication* app; | ||
|
||
@end | ||
|
||
@implementation ImagePickerFromLimitedGalleryUITests | ||
|
||
- (void)setUp { | ||
[super setUp]; | ||
// Delete the app if already exists, to test permission popups | ||
|
||
self.continueAfterFailure = NO; | ||
self.app = [[XCUIApplication alloc] init]; | ||
[self.app launch]; | ||
__weak typeof(self) weakSelf = self; | ||
[self addUIInterruptionMonitorWithDescription:@"Permission popups" | ||
handler:^BOOL(XCUIElement* _Nonnull interruptingElement) { | ||
if (@available(iOS 14, *)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think limited photos is only availabe in iOS 14? So maybe we should skip this test for ios 14 and below? This way we don't need to maintain 2 versions for this test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure how to do this. Using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sometime like this?: if (!(@available(iOS 14, *))) {
return;
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used XCTSkip, I think it is done! |
||
XCUIElement* limitedPhotoPermission = | ||
[interruptingElement.buttons elementBoundByIndex:0]; | ||
if (![limitedPhotoPermission | ||
waitForExistenceWithTimeout: | ||
kLimitedElementWaitingTime]) { | ||
os_log_error(OS_LOG_DEFAULT, "%@", | ||
weakSelf.app.debugDescription); | ||
XCTFail(@"Failed due to not able to find " | ||
@"selectPhotos butt on with %@ seconds", | ||
@(kLimitedElementWaitingTime)); | ||
} | ||
[limitedPhotoPermission tap]; | ||
} else { | ||
XCUIElement* ok = interruptingElement.buttons[@"OK"]; | ||
if (![ok waitForExistenceWithTimeout: | ||
kLimitedElementWaitingTime]) { | ||
os_log_error(OS_LOG_DEFAULT, "%@", | ||
weakSelf.app.debugDescription); | ||
XCTFail(@"Failed due to not able to find ok button " | ||
@"with %@ seconds", | ||
@(kLimitedElementWaitingTime)); | ||
} | ||
[ok tap]; | ||
} | ||
return YES; | ||
}]; | ||
} | ||
|
||
- (void)tearDown { | ||
[super tearDown]; | ||
[self.app terminate]; | ||
} | ||
|
||
- (void)testSelectingFromGallery { | ||
[self launchPickerAndSelect]; | ||
} | ||
|
||
- (void)launchPickerAndSelect { | ||
// Find and tap on the pick from gallery button. | ||
NSPredicate* predicateToFindImageFromGalleryButton = | ||
[NSPredicate predicateWithFormat:@"label == %@", @"image_picker_example_from_gallery"]; | ||
|
||
XCUIElement* imageFromGalleryButton = | ||
[self.app.otherElements elementMatchingPredicate:predicateToFindImageFromGalleryButton]; | ||
if (![imageFromGalleryButton waitForExistenceWithTimeout:kLimitedElementWaitingTime]) { | ||
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription); | ||
XCTFail(@"Failed due to not able to find image from gallery button with %@ seconds", | ||
@(kLimitedElementWaitingTime)); | ||
} | ||
|
||
XCTAssertTrue(imageFromGalleryButton.exists); | ||
[imageFromGalleryButton tap]; | ||
|
||
// Find and tap on the `pick` button. | ||
NSPredicate* predicateToFindPickButton = | ||
[NSPredicate predicateWithFormat:@"label == %@", @"PICK"]; | ||
|
||
XCUIElement* pickButton = [self.app.buttons elementMatchingPredicate:predicateToFindPickButton]; | ||
if (![pickButton waitForExistenceWithTimeout:kLimitedElementWaitingTime]) { | ||
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription); | ||
XCTFail(@"Failed due to not able to find pick button with %@ seconds", | ||
@(kLimitedElementWaitingTime)); | ||
} | ||
|
||
XCTAssertTrue(pickButton.exists); | ||
[pickButton tap]; | ||
|
||
// There is a known bug where the permission popups interruption won't get fired until a tap | ||
// happened in the app. We expect a permission popup so we do a tap here. | ||
[self.app tap]; | ||
|
||
// 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]; | ||
} else { | ||
XCUIElement* selectedPhotosCell = [self.app.cells | ||
elementMatchingPredicate:[NSPredicate | ||
predicateWithFormat:@"label == %@", @"Selected Photos"]]; | ||
if (![selectedPhotosCell waitForExistenceWithTimeout:kLimitedElementWaitingTime]) { | ||
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription); | ||
XCTFail(@"Failed due to not able to find \"Selected Photos\" cell with %@ seconds", | ||
@(kLimitedElementWaitingTime)); | ||
} | ||
[selectedPhotosCell tap]; | ||
aImage = [self.app.collectionViews elementMatchingType:XCUIElementTypeCollectionView | ||
identifier:@"PhotosGridView"] | ||
.cells.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); | ||
XCTFail(@"Failed due to not able to find an image with %@ seconds", | ||
@(kLimitedElementWaitingTime)); | ||
} | ||
XCTAssertTrue(aImage.exists); | ||
[aImage tap]; | ||
|
||
// Find and tap on the `Done` button. | ||
NSPredicate* predicateToFindDoneButton = | ||
[NSPredicate predicateWithFormat:@"label == %@", @"Done"]; | ||
|
||
XCUIElement* doneButton = [self.app.buttons elementMatchingPredicate:predicateToFindDoneButton]; | ||
if (![doneButton waitForExistenceWithTimeout:kLimitedElementWaitingTime]) { | ||
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription); | ||
XCTFail(@"Failed due to not able to find Cancel button with %@ seconds", | ||
@(kLimitedElementWaitingTime)); | ||
} | ||
|
||
XCTAssertTrue(doneButton.exists); | ||
[doneButton tap]; | ||
|
||
// Find an image and tap on it to have access to selected photos. | ||
if (@available(iOS 14, *)) { | ||
aImage = [self.app.scrollViews.firstMatch.images elementBoundByIndex:1]; | ||
} else { | ||
XCUIElement* selectedPhotosCell = [self.app.cells | ||
elementMatchingPredicate:[NSPredicate | ||
predicateWithFormat:@"label == %@", @"Selected Photos"]]; | ||
if (![selectedPhotosCell waitForExistenceWithTimeout:kLimitedElementWaitingTime]) { | ||
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription); | ||
XCTFail(@"Failed due to not able to find \"Selected Photos\" cell with %@ seconds", | ||
@(kLimitedElementWaitingTime)); | ||
} | ||
[selectedPhotosCell tap]; | ||
aImage = [self.app.collectionViews elementMatchingType:XCUIElementTypeCollectionView | ||
identifier:@"PhotosGridView"] | ||
.cells.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); | ||
XCTFail(@"Failed due to not able to find an image with %@ seconds", | ||
@(kLimitedElementWaitingTime)); | ||
} | ||
XCTAssertTrue(aImage.exists); | ||
[aImage tap]; | ||
|
||
// Find the picked image. | ||
NSPredicate* predicateToFindPickedImage = | ||
[NSPredicate predicateWithFormat:@"label == %@", @"image_picker_example_picked_image"]; | ||
|
||
XCUIElement* pickedImage = [self.app.images elementMatchingPredicate:predicateToFindPickedImage]; | ||
if (![pickedImage waitForExistenceWithTimeout:kLimitedElementWaitingTime]) { | ||
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription); | ||
XCTFail(@"Failed due to not able to find pickedImage with %@ seconds", | ||
@(kLimitedElementWaitingTime)); | ||
} | ||
|
||
XCTAssertTrue(pickedImage.exists); | ||
} | ||
|
||
@end |
Uh oh!
There was an error while loading. Please reload this page.