2016-07-26 22 views
2

目前我訪問照片庫,拿起照片通過以下方式:使用如何在Xcode的UITests下從UIImagePickerController的某個索引處選擇圖像?

extension XCUIApplication { 

    func pickPhotoFromImagePickerAtIndex(index: UInt) { 

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

例子:有時

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

這種方法崩潰。這取決於畫廊中的照片。

有沒有辦法以更優雅和有效的方式做到這一點?

回答

1

我假設,你需要點擊的索引是從集合視圖的底部算起的。如果是這樣,那麼你可以重新設計你的方法:

func pickPhotoFromImagePickerAtInvertedIndex(index: UInt) { 

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