@@ -59,103 +59,96 @@ - (void)tearDown {
5959 [self .app terminate ];
6060}
6161
62- - (void )testPickingFromGallery {
63- [self launchPickerAndPick ];
64- }
65-
6662- (void )testCancel {
67- [self launchPickerAndCancel ];
68- }
69-
70- - (void )launchPickerAndCancel {
7163 // Find and tap on the pick from gallery button.
72- NSPredicate *predicateToFindImageFromGalleryButton =
73- [NSPredicate predicateWithFormat: @" label == %@" , @" image_picker_example_from_gallery" ];
74-
7564 XCUIElement *imageFromGalleryButton =
76- [ self .app.otherElements elementMatchingPredicate: predicateToFindImageFromGalleryButton] ;
65+ self.app .otherElements [ @" image_picker_example_from_gallery " ]. firstMatch ;
7766 if (![imageFromGalleryButton waitForExistenceWithTimeout: kElementWaitingTime ]) {
7867 os_log_error (OS_LOG_DEFAULT, " %@" , self.app .debugDescription );
7968 XCTFail (@" Failed due to not able to find image from gallery button with %@ seconds" ,
8069 @(kElementWaitingTime ));
8170 }
8271
83- XCTAssertTrue (imageFromGalleryButton.exists );
8472 [imageFromGalleryButton tap ];
8573
8674 // Find and tap on the `pick` button.
87- NSPredicate *predicateToFindPickButton =
88- [NSPredicate predicateWithFormat: @" label == %@" , @" PICK" ];
89-
90- XCUIElement *pickButton = [self .app.buttons elementMatchingPredicate: predicateToFindPickButton];
75+ XCUIElement *pickButton = self.app .buttons [@" PICK" ].firstMatch ;
9176 if (![pickButton waitForExistenceWithTimeout: kElementWaitingTime ]) {
9277 os_log_error (OS_LOG_DEFAULT, " %@" , self.app .debugDescription );
9378 XCTFail (@" Failed due to not able to find pick button with %@ seconds" , @(kElementWaitingTime ));
9479 }
9580
96- XCTAssertTrue (pickButton.exists );
9781 [pickButton tap ];
9882
9983 // There is a known bug where the permission popups interruption won't get fired until a tap
10084 // happened in the app. We expect a permission popup so we do a tap here.
10185 [self .app tap ];
10286
10387 // Find and tap on the `Cancel` button.
104- NSPredicate *predicateToFindCancelButton =
105- [NSPredicate predicateWithFormat: @" label == %@" , @" Cancel" ];
106-
107- XCUIElement *cancelButton =
108- [self .app.buttons elementMatchingPredicate: predicateToFindCancelButton];
88+ XCUIElement *cancelButton = self.app .buttons [@" Cancel" ].firstMatch ;
10989 if (![cancelButton waitForExistenceWithTimeout: kElementWaitingTime ]) {
11090 os_log_error (OS_LOG_DEFAULT, " %@" , self.app .debugDescription );
11191 XCTFail (@" Failed due to not able to find Cancel button with %@ seconds" ,
11292 @(kElementWaitingTime ));
11393 }
11494
115- XCTAssertTrue (cancelButton.exists );
11695 [cancelButton tap ];
11796
11897 // Find the "not picked image text".
119- XCUIElement *imageNotPickedText = [self .app.staticTexts
120- elementMatchingPredicate: [NSPredicate
121- predicateWithFormat: @" label == %@ " ,
122- @" You have not yet picked an image." ]];
98+ XCUIElement *imageNotPickedText =
99+ self.app .staticTexts [@" You have not yet picked an image." ].firstMatch ;
123100 if (![imageNotPickedText waitForExistenceWithTimeout: kElementWaitingTime ]) {
124101 os_log_error (OS_LOG_DEFAULT, " %@" , self.app .debugDescription );
125102 XCTFail (@" Failed due to not able to find imageNotPickedText with %@ seconds" ,
126103 @(kElementWaitingTime ));
127104 }
105+ }
128106
129- XCTAssertTrue (imageNotPickedText.exists );
107+ - (void )testPickingFromGallery {
108+ [self launchPickerAndPickWithMaxWidth: nil maxHeight: nil quality: nil ];
130109}
131110
132- - (void )launchPickerAndPick {
133- // Find and tap on the pick from gallery button.
134- NSPredicate *predicateToFindImageFromGalleryButton =
135- [NSPredicate predicateWithFormat: @" label == %@" , @" image_picker_example_from_gallery" ];
111+ - (void )testPickingWithContraintsFromGallery {
112+ [self launchPickerAndPickWithMaxWidth: @200 maxHeight: @100 quality: @50 ];
113+ }
136114
115+ - (void )launchPickerAndPickWithMaxWidth : (NSNumber *)maxWidth
116+ maxHeight : (NSNumber *)maxHeight
117+ quality : (NSNumber *)quality {
118+ // Find and tap on the pick from gallery button.
137119 XCUIElement *imageFromGalleryButton =
138- [ self .app.otherElements elementMatchingPredicate: predicateToFindImageFromGalleryButton] ;
120+ self.app .otherElements [ @" image_picker_example_from_gallery " ]. firstMatch ;
139121 if (![imageFromGalleryButton waitForExistenceWithTimeout: kElementWaitingTime ]) {
140122 os_log_error (OS_LOG_DEFAULT, " %@" , self.app .debugDescription );
141123 XCTFail (@" Failed due to not able to find image from gallery button with %@ seconds" ,
142124 @(kElementWaitingTime ));
143125 }
144-
145- XCTAssertTrue (imageFromGalleryButton.exists );
146126 [imageFromGalleryButton tap ];
147127
148- // Find and tap on the `pick` button.
149- NSPredicate *predicateToFindPickButton =
150- [NSPredicate predicateWithFormat: @" label == %@" , @" PICK" ];
128+ if (maxWidth != nil ) {
129+ XCUIElement *field = self.app .textFields [@" Enter maxWidth if desired" ].firstMatch ;
130+ [field tap ];
131+ [field typeText: maxWidth.stringValue];
132+ }
133+
134+ if (maxHeight != nil ) {
135+ XCUIElement *field = self.app .textFields [@" Enter maxHeight if desired" ].firstMatch ;
136+ [field tap ];
137+ [field typeText: maxHeight.stringValue];
138+ }
151139
152- XCUIElement *pickButton = [self .app.buttons elementMatchingPredicate: predicateToFindPickButton];
140+ if (quality != nil ) {
141+ XCUIElement *field = self.app .textFields [@" Enter quality if desired" ].firstMatch ;
142+ [field tap ];
143+ [field typeText: quality.stringValue];
144+ }
145+
146+ // Find and tap on the `pick` button.
147+ XCUIElement *pickButton = self.app .buttons [@" PICK" ].firstMatch ;
153148 if (![pickButton waitForExistenceWithTimeout: kElementWaitingTime ]) {
154149 os_log_error (OS_LOG_DEFAULT, " %@" , self.app .debugDescription );
155150 XCTFail (@" Failed due to not able to find pick button with %@ seconds" , @(kElementWaitingTime ));
156151 }
157-
158- XCTAssertTrue (pickButton.exists );
159152 [pickButton tap ];
160153
161154 // There is a known bug where the permission popups interruption won't get fired until a tap
@@ -167,8 +160,7 @@ - (void)launchPickerAndPick {
167160 if (@available (iOS 14 , *)) {
168161 aImage = [self .app.scrollViews.firstMatch.images elementBoundByIndex: 1 ];
169162 } else {
170- XCUIElement *allPhotosCell = [self .app.cells
171- elementMatchingPredicate: [NSPredicate predicateWithFormat: @" label == %@" , @" All Photos" ]];
163+ XCUIElement *allPhotosCell = self.app .cells [@" All Photos" ].firstMatch ;
172164 if (![allPhotosCell waitForExistenceWithTimeout: kElementWaitingTime ]) {
173165 os_log_error (OS_LOG_DEFAULT, " %@" , self.app .debugDescription );
174166 XCTFail (@" Failed due to not able to find \" All Photos\" cell with %@ seconds" ,
@@ -184,20 +176,14 @@ - (void)launchPickerAndPick {
184176 os_log_error (OS_LOG_DEFAULT, " %@" , self.app .debugDescription );
185177 XCTFail (@" Failed due to not able to find an image with %@ seconds" , @(kElementWaitingTime ));
186178 }
187- XCTAssertTrue (aImage.exists );
188179 [aImage tap ];
189180
190181 // Find the picked image.
191- NSPredicate *predicateToFindPickedImage =
192- [NSPredicate predicateWithFormat: @" label == %@" , @" image_picker_example_picked_image" ];
193-
194- XCUIElement *pickedImage = [self .app.images elementMatchingPredicate: predicateToFindPickedImage];
182+ XCUIElement *pickedImage = self.app .images [@" image_picker_example_picked_image" ].firstMatch ;
195183 if (![pickedImage waitForExistenceWithTimeout: kElementWaitingTime ]) {
196184 os_log_error (OS_LOG_DEFAULT, " %@" , self.app .debugDescription );
197185 XCTFail (@" Failed due to not able to find pickedImage with %@ seconds" , @(kElementWaitingTime ));
198186 }
199-
200- XCTAssertTrue (pickedImage.exists );
201187}
202188
203189@end
0 commit comments