【问题标题】:How to pick an image at some index from UIImagePickerController under UITests in Xcode?如何从 Xcode 中 UITests 下的 UIImagePickerController 中的某个索引处选择图像?
【发布时间】:2016-07-26 13:29:57
【问题描述】:

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

extension XCUIApplication {

    func pickPhotoFromImagePickerAtIndex(index: UInt) {

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

使用示例:

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

此方法有时会崩溃。这取决于画廊中的照片。

有什么方法可以更优雅、更有效地做到这一点?

【问题讨论】:

    标签: ios swift uitest


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2023-03-09
      • 2017-10-30
      • 2015-06-11
      • 2012-10-17
      • 1970-01-01
      • 1970-01-01
      • 2012-07-24
      • 1970-01-01
      相关资源
      最近更新 更多