如何在Xcode的UITests下的UIImagePickerController的某个索引处选择图像? [英] How to pick an image at some index from UIImagePickerController under UITests in Xcode?

查看:135
本文介绍了如何在Xcode的UITests下的UIImagePickerController的某个索引处选择图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我通过以下方式访问照片库并拍照:

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)
    }
}

使用示例:

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?

推荐答案

我认为,您需要点击的索引是从集合视图的底部开始计算的.如果是这样,那么您可以重新设计您的方法:

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()
}

这篇关于如何在Xcode的UITests下的UIImagePickerController的某个索引处选择图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆