I am writing UI automation tests in XCode and need to select a photo from the Camera Roll screen that pops up in my app. I looked online but can't seem to find any information on how to do this. Does anyone know if this is possible?
Asked
Active
Viewed 1,219 times
1
-
Checkout this link, it may help... [Pick image from UIImagePickerController-UIAutomation](https://stackoverflow.com/questions/29490728/how-to-use-uiautomation-to-select-image-from-uiimagepickercontroller) – Prajnaranjan Das Feb 16 '18 at 09:16
-
Try using the record tool – Oletha Feb 17 '18 at 11:03
2 Answers
2
The code from the other StackOverflow question didn't work so I figured it out myself. Tapping on the photo itself didn't work but tapping on the coordinate location of the photo seems to work fine.
let image = Page.app.collectionViews.children(matching: .cell).element(boundBy: 0)
let coord:XCUICoordinate = image.coordinate(withNormalizedOffset: CGVector.init(dx: 0.0, dy: 0.0))
coord.tap()

C J
- 567
- 2
- 4
- 11
-
1
-
This worked well! I required a second tap with a pause in between since I had a lot of photos on the device I was using for testing. – Steig Apr 30 '19 at 17:58
-
1
Swift 4+ Automation for choosing image
//Title For Photos
XCTAssertTrue(XCUIApplication().navigationBars.otherElements["Photos"].waitForExistence(timeout: 5))
//Check if Moments is visible on the view
XCTAssertTrue(XCUIApplication().otherElements.tables.cells["Moments"].waitForExistence(timeout: 5))
//Click on Moments to see the image collection list
XCUIApplication().otherElements.tables.cells["Moments"].tap()
//Checking for "Photo, Portrait, August 08, 2012, 11:29 PM" exist
XCTAssertTrue(XCUIApplication().otherElements.collectionViews.cells["Photo, Landscape, August 08, 2012, 8:52 PM"].waitForExistence(timeout: 5))
//Clicking on "Photo, Portrait, August 08, 2012, 11:29 PM"
XCUIApplication().otherElements.collectionViews.cells["Photo, Landscape, August 08, 2012, 8:52 PM"].tap()

Community
- 1
- 1

Sipho Motha
- 11
- 3
-
-
-
1@brainray may be do your localization on setup override func setUp() { super.setUp() continueAfterFailure = false XCUIApplication().launchArguments += [“-AppleLanguages”, “(fr)”] XCUIApplication().launchArguments += [“-AppleLocale”, “fr_FR”] XCUIApplication().launch() } – Sipho Motha Jan 17 '23 at 20:46