2016-07-26 19 views
2

Derzeit greife ich auf Fotogalerie und ein Foto die folgende Art und Weise holen:Wie ein Bild an einem Index von UIImagePickerController unter UITests in Xcode auswählen?

extension XCUIApplication { 

    func pickPhotoFromImagePickerAtIndex(index: UInt) { 

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

Beispiel:

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

Diese Methode stürzt manchmal. Es hängt von Fotos in der Galerie ab.

Gibt es eine Möglichkeit, dies eleganter und effektiver zu tun?

Antwort

1

Ich nehme an, dass der Index, den Sie antippen müssen, vom unteren Rand der Sammlungsansicht gezählt wird. Wenn ja, dann können Sie Ihre Methode neu gestalten:

func pickPhotoFromImagePickerAtInvertedIndex(index: UInt) { 

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