Ong Pe Hon
Ong Pe Hon

Reputation: 345

UITest DateTimePicker

I'm trying to UITest a form Built with Eureka forms on my iOS Swift project.

Here's how the picker wheel looks. Its a TimeRow() on Eureka enter image description here

The problem is my UITest is unable to move the DateField. Its only able to move the hours and minutes field. Here's the UITtest code

func testSetTime() {
        app.tables.cells.containing(.staticText, identifier: "Departure Time").element.tap()

        // unable to get this to work.
        app.datePickers.pickerWheels.element(boundBy: 0).adjust(toPickerWheelValue: "May 14")

        // these lines work perfectly.
        app.datePickers.pickerWheels.element(boundBy: 1).adjust(toPickerWheelValue: "01")
        app.datePickers.pickerWheels.element(boundBy: 2).adjust(toPickerWheelValue: "00")
        app.buttons["Done"].firstMatch.tap()
}

The error after running is as follows.

Unable to find current value 'May 17' in possible values 28 Mar, 29 Mar, 30 Mar, 31 Mar, 1 Apr, 2 Apr, 3 Apr, 4 Apr, 5 Apr, 6 Apr, 7 Apr, 8 Apr, 9 Apr, 10 Apr, 11 Apr, 12 Apr, 13 Apr, 14 Apr, 15 Apr, 16 Apr, 17 Apr, 18 Apr, 19 Apr, 20 Apr, 21 Apr, 22 Apr, 23 Apr, 24 Apr, 25 Apr, 26 Apr, 27 Apr, 28 Apr, 29 Apr, 30 Apr, 1 May, 2 May, 3 May, 4 May, 5 May, 6 May, 7 May, 8 May, 9 May, 10 May, 11 May, 12 May, 13 May, 14 May, 15 May, 16 May, 17 May, 18 May, 19 May, 20 May, 21 May, 22 May, 23 May, 24 May, 25 May, 26 May, 27 May, 28 May, 29 May, 30 May, 31 May, 1 Jun, 2 Jun, 3 Jun, 4 Jun, 5 Jun, 6 Jun, 7 Jun, 8 Jun, 9 Jun, 10 Jun, 11 Jun, 12 Jun, 13 Jun, 14 Jun, 15 Jun, 16 Jun, 17 Jun, 18 Jun, 19 Jun, 20 Jun, 21 Jun, 22 Jun, 23 Jun, 24 Jun, 25 Jun, 26 Jun, 27 Jun, 28 Jun, 29 Jun, 30 Jun, 1 Jul, 2 Jul, 3 Jul, 4 Jul, 5 Jul for the picker wheel "Today" PickerWheel

Upvotes: 0

Views: 459

Answers (2)

aakash tandukar
aakash tandukar

Reputation: 130

app.pickerWheels.element(boundBy: 0).adjust(toPickerWheelValue: "5")
app.pickerWheels.element(boundBy: 1).adjust(toPickerWheelValue: "June")
app.pickerWheels.element(boundBy: 2).adjust(toPickerWheelValue: "1998")

Upvotes: 1

Roman Zakharov
Roman Zakharov

Reputation: 2273

Well, the framework specifies the problem fully you should use 17 May instead of May 17.

app.pickerWheels.firstMatch.adjust(toPickerWheelValue: "17 May")

UPD

I have tried to interact with alike picker in the Calendar app (Xcode 11.4)

Works just fine

class siguiente: XCTestCase {

    func testExample() {
        // Given 
        let app = XCTApps.calendar.app
        app.launch()
        app.buttons["Add"].tap()
        app.staticTexts["Starts"].tap()

        // When
        let dateWheel = app.pickerWheels.firstMatch
        app.pickerWheels.firstMatch.adjust(toPickerWheelValue: "May 21")

        // Then
        XCTAssertEqual(dateWheel.value as? String, "Thu, May 21")
    }
}

Upvotes: 1

Related Questions