Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use UIAutomation to select image from UIImagePickerController

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!

Instruments Run Output

like image 628
Brian Trzupek Avatar asked Apr 07 '15 11:04

Brian Trzupek


People also ask

How do I use image picker in Swift?

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.

What is Uiimagepickercontroller?

A view controller that manages the system interfaces for taking pictures, recording movies, and choosing items from the user's media library.


2 Answers

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.

like image 163
Zeeshan Avatar answered Nov 15 '22 04:11

Zeeshan


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!

like image 37
Brian Trzupek Avatar answered Nov 15 '22 05:11

Brian Trzupek