1

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?

C J
  • 567
  • 2
  • 4
  • 11
  • 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 Answers2

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

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
  • What is your question? – Swifty Jun 10 '19 at 13:20
  • And how do you get that for i18n-ized apps? – brainray Jan 16 '23 at 19:30
  • 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