I am currently working on a SwiftUI project and I am trying to write a UI test for a DatePicker. However, I am having trouble interacting with the DatePicker in the test. Here is the code for the DatePicker in my SwiftUI view:
DatePicker("Date", selection: $date, displayedComponents: [.date])
.datePickerStyle(.graphical)
.labelsHidden()
.frame(width: 150)
And here is the code for my UI test:
func testSelectingDateChangesMainView() throws {
let app = XCUIApplication()
app.launch()
let dateDatePicker: XCUIElement = app.windows["mainUI-AppWindow-1"].datePickers["Date"]
dateDatePicker.click()
let col = dateDatePicker.descendants(matching: .any)
print("\(dateDatePicker.debugDescription), \(col.debugDescription)")
}
When I run the test, it seems like the DatePicker does not have any descendants, so I am unable to select a date.
Does anyone have any suggestions on how I can interact with a .graphical
style DatePicker in a UI test? Any help would be greatly appreciated.
Thank you, OnlyForF1