How to use UIAutomation to select image from UIImagePickerController

独自空忆成欢 提交于 2019-12-04 03:24:50

问题


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!


回答1:


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.




回答2:


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




回答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!



来源:https://stackoverflow.com/questions/29490728/how-to-use-uiautomation-to-select-image-from-uiimagepickercontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!