6

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

Brian Trzupek
  • 4,982
  • 1
  • 16
  • 19

3 Answers3

5

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.

Zeeshan
  • 4,194
  • 28
  • 32
3

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!

Brian Trzupek
  • 4,982
  • 1
  • 16
  • 19
  • @Tareq ..if you have found that please let me know as well. – Yugandhar Pathi Oct 08 '18 at 21:40
  • @YugandharPathi I have spent a lot of time researching this and basically you can't, since iOS 11 apple put UIImagePickerController outside the app view hierarchy so you can't access it A workaround for this I'm using is to use mock and load your component with preloaded image to keep the tests running, I simply had a variable in my .env file called TESTING and whenever detox is going to make a new build, my testing script will set that variable to true Then inside my code I check on that variable, if it's true I load a dummy data for any procedures I can't make the detox make – Tareq El-Masri Oct 10 '18 at 09:22
  • @TareqEl-Masri Thanks a lot! can you please let me know how can you run test scripts while running detox. Do you have any detox configuration for that ? – Yugandhar Pathi Oct 12 '18 at 21:57
3

First I pick the moments row, and then I select the photo. Later I click the button choose that confirms the picked image.

    let moments = app.tables.cells.element(boundBy: 0)
    moments.tap()
    sleep(3)
    let selectedPhoto = app.collectionViews.element(boundBy: 0).cells.element(boundBy: 0)
    sleep(3)
    selectedPhoto.tap()
    sleep(3)
    //Choose Button
    let chooseButton = app.buttons.element(boundBy: 1)
    chooseButton.tap()

Hope it helps