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

1

2

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?

Collage answered 26/7, 2016 at 13:29 Comment(0)
L
3

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()
}
Lusaka answered 27/7, 2016 at 9:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.