How to pick an image at some index from UIImagePickerController under UITests in Xcode?

有些话、适合烂在心里 提交于 2020-02-03 22:02:36

问题


Currently I access photo gallery and pick up a photo the following way:

extension XCUIApplication {

    func pickPhotoFromImagePickerAtIndex(index: UInt) {

        tables.buttons["Moments"].tap()
        collectionViews["PhotosGridView"].tapCellAtIndex(index)
    }
}

Example of use:

photosCollectionView.tapCellAtIndex(0)
app.pickPhotoFromImagePickerAtIndex(5)

This method crashes sometimes. It depends on photos in gallery.

Is there any way to do this in more elegant and effective way?


回答1:


I assume, that index you need to tap is counted from the bottom of the collection view. If so, then you can redesign your method:

func pickPhotoFromImagePickerAtInvertedIndex(index: UInt) {

    tables.buttons["Camera Roll"].tap()
    let collectionView = collectionViews["PhotosGridView"]
    collectionView.cells.elementBoundByIndex(collectionView.cells.count - 1 - index).tap()
}


来源:https://stackoverflow.com/questions/38591260/how-to-pick-an-image-at-some-index-from-uiimagepickercontroller-under-uitests-in

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