Search code examples
swift3xcode8ios-ui-automation

ui test xcode, handle datepicker


i really stuck at this problem i cant swipe and then select the year at this datepicker, maybe some experienced on automation can give solution this tupe of datepicker i wabt to handle

i had code from result of recorded test like below,

let datePickersQuery = app.datePickers
    let pickerWheel = datePickersQuery.pickerWheels["2000"]
    pickerWheel.tap()
    pickerWheel.

    let pickerWheel2 = datePickersQuery.pickerWheels["1996"]
    pickerWheel2.tap()

but still force close when running the test


Solution

  • You interact with date pickers a little differently and I have never seen recorded tests "get it right". You should use app.datePickers["Your matcher"].adjust(toPickerWheelValue: <String>) in order to set a value for a picker.

    If you're having trouble with your date picker query, you can specify the index of which picker wheel you want to set by app.datePickers.element(boundBy: <UInt>).

    Here's the link to the apple reference doc https://developer.apple.com/reference/xctest/xcuielement/1618672-adjust