@@ -59,103 +59,96 @@ - (void)tearDown {
59
59
[self .app terminate ];
60
60
}
61
61
62
- - (void )testPickingFromGallery {
63
- [self launchPickerAndPick ];
64
- }
65
-
66
62
- (void )testCancel {
67
- [self launchPickerAndCancel ];
68
- }
69
-
70
- - (void )launchPickerAndCancel {
71
63
// Find and tap on the pick from gallery button.
72
- NSPredicate *predicateToFindImageFromGalleryButton =
73
- [NSPredicate predicateWithFormat: @" label == %@" , @" image_picker_example_from_gallery" ];
74
-
75
64
XCUIElement *imageFromGalleryButton =
76
- [ self .app.otherElements elementMatchingPredicate: predicateToFindImageFromGalleryButton] ;
65
+ self.app .otherElements [ @" image_picker_example_from_gallery " ]. firstMatch ;
77
66
if (![imageFromGalleryButton waitForExistenceWithTimeout: kElementWaitingTime ]) {
78
67
os_log_error (OS_LOG_DEFAULT, " %@" , self.app .debugDescription );
79
68
XCTFail (@" Failed due to not able to find image from gallery button with %@ seconds" ,
80
69
@(kElementWaitingTime ));
81
70
}
82
71
83
- XCTAssertTrue (imageFromGalleryButton.exists );
84
72
[imageFromGalleryButton tap ];
85
73
86
74
// 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 ;
91
76
if (![pickButton waitForExistenceWithTimeout: kElementWaitingTime ]) {
92
77
os_log_error (OS_LOG_DEFAULT, " %@" , self.app .debugDescription );
93
78
XCTFail (@" Failed due to not able to find pick button with %@ seconds" , @(kElementWaitingTime ));
94
79
}
95
80
96
- XCTAssertTrue (pickButton.exists );
97
81
[pickButton tap ];
98
82
99
83
// There is a known bug where the permission popups interruption won't get fired until a tap
100
84
// happened in the app. We expect a permission popup so we do a tap here.
101
85
[self .app tap ];
102
86
103
87
// 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 ;
109
89
if (![cancelButton waitForExistenceWithTimeout: kElementWaitingTime ]) {
110
90
os_log_error (OS_LOG_DEFAULT, " %@" , self.app .debugDescription );
111
91
XCTFail (@" Failed due to not able to find Cancel button with %@ seconds" ,
112
92
@(kElementWaitingTime ));
113
93
}
114
94
115
- XCTAssertTrue (cancelButton.exists );
116
95
[cancelButton tap ];
117
96
118
97
// 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 ;
123
100
if (![imageNotPickedText waitForExistenceWithTimeout: kElementWaitingTime ]) {
124
101
os_log_error (OS_LOG_DEFAULT, " %@" , self.app .debugDescription );
125
102
XCTFail (@" Failed due to not able to find imageNotPickedText with %@ seconds" ,
126
103
@(kElementWaitingTime ));
127
104
}
105
+ }
128
106
129
- XCTAssertTrue (imageNotPickedText.exists );
107
+ - (void )testPickingFromGallery {
108
+ [self launchPickerAndPickWithMaxWidth: nil maxHeight: nil quality: nil ];
130
109
}
131
110
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
+ }
136
114
115
+ - (void )launchPickerAndPickWithMaxWidth : (NSNumber *)maxWidth
116
+ maxHeight : (NSNumber *)maxHeight
117
+ quality : (NSNumber *)quality {
118
+ // Find and tap on the pick from gallery button.
137
119
XCUIElement *imageFromGalleryButton =
138
- [ self .app.otherElements elementMatchingPredicate: predicateToFindImageFromGalleryButton] ;
120
+ self.app .otherElements [ @" image_picker_example_from_gallery " ]. firstMatch ;
139
121
if (![imageFromGalleryButton waitForExistenceWithTimeout: kElementWaitingTime ]) {
140
122
os_log_error (OS_LOG_DEFAULT, " %@" , self.app .debugDescription );
141
123
XCTFail (@" Failed due to not able to find image from gallery button with %@ seconds" ,
142
124
@(kElementWaitingTime ));
143
125
}
144
-
145
- XCTAssertTrue (imageFromGalleryButton.exists );
146
126
[imageFromGalleryButton tap ];
147
127
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
+ }
151
139
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 ;
153
148
if (![pickButton waitForExistenceWithTimeout: kElementWaitingTime ]) {
154
149
os_log_error (OS_LOG_DEFAULT, " %@" , self.app .debugDescription );
155
150
XCTFail (@" Failed due to not able to find pick button with %@ seconds" , @(kElementWaitingTime ));
156
151
}
157
-
158
- XCTAssertTrue (pickButton.exists );
159
152
[pickButton tap ];
160
153
161
154
// There is a known bug where the permission popups interruption won't get fired until a tap
@@ -167,8 +160,7 @@ - (void)launchPickerAndPick {
167
160
if (@available (iOS 14 , *)) {
168
161
aImage = [self .app.scrollViews.firstMatch.images elementBoundByIndex: 1 ];
169
162
} else {
170
- XCUIElement *allPhotosCell = [self .app.cells
171
- elementMatchingPredicate: [NSPredicate predicateWithFormat: @" label == %@" , @" All Photos" ]];
163
+ XCUIElement *allPhotosCell = self.app .cells [@" All Photos" ].firstMatch ;
172
164
if (![allPhotosCell waitForExistenceWithTimeout: kElementWaitingTime ]) {
173
165
os_log_error (OS_LOG_DEFAULT, " %@" , self.app .debugDescription );
174
166
XCTFail (@" Failed due to not able to find \" All Photos\" cell with %@ seconds" ,
@@ -184,20 +176,14 @@ - (void)launchPickerAndPick {
184
176
os_log_error (OS_LOG_DEFAULT, " %@" , self.app .debugDescription );
185
177
XCTFail (@" Failed due to not able to find an image with %@ seconds" , @(kElementWaitingTime ));
186
178
}
187
- XCTAssertTrue (aImage.exists );
188
179
[aImage tap ];
189
180
190
181
// 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 ;
195
183
if (![pickedImage waitForExistenceWithTimeout: kElementWaitingTime ]) {
196
184
os_log_error (OS_LOG_DEFAULT, " %@" , self.app .debugDescription );
197
185
XCTFail (@" Failed due to not able to find pickedImage with %@ seconds" , @(kElementWaitingTime ));
198
186
}
199
-
200
- XCTAssertTrue (pickedImage.exists );
201
187
}
202
188
203
189
@end
0 commit comments