How to add an image for multiple locales using XCTest

An annoying thing I’ve had to deal with recently is adding an image (both where you take a photo with the camera and also from the gallery).

You might think that sounds pretty straight forward, but when you want to run your test in multiple locales then “Choose from library” and “Upload photo” etc just doesn’t quite cut it.

Attempts to record the steps I took within the gallery view also proved futile, as I could not actually record what I did there.

Here is how I went about adding images to my tests:

    func testAddPhoto() {

        let addPhotoButton = app.tabBars.buttons[LocalizedString(\”add.photo.button\”)].firstMatch

        let photoLibraryButton = app.staticTexts[LocalizedString(\”photo.library.button\”)].firstMatch

        let takePhotoButton = app.staticTexts[LocalizedString(\”take.photo.button\”)].firstMatch

        addPhotoButton.tap()

        XCTAssertEqual(waiterResultWithExpectation(photoLibraryButton), .completed)

        XCTAssertTrue(photoLibraryButton.isEnabled)

        XCTAssertTrue(takePhotoButton.isEnabled)

        photoLibraryButton.tap()

        //here I am selecting the first image album

        app.cells.element(boundBy:0).tap()

        //opted for a sleep to give it time for the images to appear

        sleep(1)

        //selecting the most recent image

        app.cells.element(boundBy:0).tap()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s