We are trying to get a UIAutomation test around a flow in our app where a user selects an image from a UIImagePickerController. All the automation works great, until we try to select an image from the picker controller. It seems like we cannot get the right object to send the tap to. Here is what we are trying:
UIALogger.logMessage("Navigation Title: " + app.navigationTitle() );
window.collectionViews()[0].tapWithOptions({tapOffset:{x:0.5, y:0.5}});
The above will show the navigation title as "Moments", which means we are in the photo picker, but the second line gets no error - but does not select anything (no matter the coordinates).
The test ultimately fails being stuck on the photo selection screen.
I logged the element tree below, and you can see that it appears that there is a UICollectionView out there, but all the cells are the section headers and there are none in the debug log output that are actual 'photos'.
So how do we select an image from a UIImagePickerController with UIAutomation?
Thanks!
storyboard file and add two elements inside the view controller. The first one is a button, which will show up an image picker modal whenever it gets pressed. The second one is an image view. I'm going to put a placeholder image at first, but once the user selected an image, we'll display that image to that view.
A view controller that manages the system interfaces for taking pictures, recording movies, and choosing items from the user's media library.
I fixed this by
app.tables.cells.element(boundBy: 1).tap()
// this table has two rows // 1- Moments // 2- Camera role
app.collectionViews["PhotosGridView"].cells["Photo, Landscape, January 11, 6:34 PM"].tap() // I want to select this item from moments
It is working.
So, I figured this out. Duh. I just needed to access the visible cells and send the tap to one of those. Works like a charm.
window.collectionViews()[0].visibleCells()[0].tap();
I hope this helps someone else!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With