Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pick image from photos/gallery using xctest

I am writing a test framework for an ios app that requires importing image from photos/gallery app for validation. I am using XCTest Framework for testing. I have looked over the Internet for some resources but couldn't find any. Can anyone help me how to approach the problem. Again, I have pick the image not from inside the app but from image but from Photos library.

like image 518
sajal garg Avatar asked Apr 11 '17 09:04

sajal garg


2 Answers

Yes

You can access the photo library but it require XCUITest and the recorder doesn't work inside of Apple's UIRemoteView's like the photo picker. What you have to do is get to the photo picker inside an XCUITest, set a breakpoint, then inspect the view hierarchy to find the elements that are able to be navigated with XCUITest. The example below works with the pictures that come with the simulator.

    let app = XCUIApplication()
    // get to the photo library
    // set a breakpoint, po [[UIWindow keyWindow] recursiveDescription]
    let tablesQuery = app.tables
    app.sheets.buttons["Choose From Library"].tap()
    app.cells["Camera Roll"].tap()
    app.cells["Photo, Landscape, March 12, 2011, 7:17 PM"].tap()
like image 170
Steve Moser Avatar answered Sep 30 '22 06:09

Steve Moser


let photosApp = XCUIApplication(bundleIdentifier: "com.apple.mobileslideshow")
photosApp.launch()

let continueButton = photosApp.buttons["Continue"]
if continueButton.waitForExistence(timeout: 2) {
  continueButton.tap()
}
photosApp.collectionViews["PhotosGridView"].cells.firstMatch.tap()
like image 36
Calin Drule Avatar answered Sep 30 '22 07:09

Calin Drule