简体   繁体   English

如何使用UIAutomation从UIImagePickerController中选择图像

[英]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. 我们正试图在我们的应用程序中围绕流程进行UIAutomation测试,其中用户从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). 以上将导航标题显示为“Moments”,这意味着我们在照片选择器中,但第二行没有错误 - 但不选择任何内容(无论坐标)。

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'. 我记录了下面的元素树,你可以看到它看起来有一个UICollectionView,但所有的单元格都是节头,调试日志输出中没有实际的“照片”。

So how do we select an image from a UIImagePickerController with UIAutomation? 那么我们如何使用UIAutomation从UIImagePickerController中选择一个图像呢?

Thanks! 谢谢!

仪器运行输出

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. 这是工作。

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 希望能帮助到你

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! 我希望这有助于其他人!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM