I have defined a DatePicker to have the compact style, as follows:
struct ContentView: View {
@State private var selectedDate = Date()
var body: some View {
DatePicker("Date Selected", selection: $selectedDate, displayedComponents: [.date])
.accessibilityIdentifier("DatePicker")
.datePickerStyle(.compact)
}
}
I have defined a UI test that:
- Taps on the DatePicker to show the DatePicker popup; then
- Taps on one of the dates in the DatePicker popup to select that date; and then
- Taps on the DatePicker again to dismiss the DatePicker popup.
Here's the code:
func test_date_picker() {
let application = XCUIApplication()
// 0. Launch the app
application.launch()
// 1. Show the DatePicker popup
application.datePickers["DatePicker"].tap()
// 2. Change the selected date
application.datePickers.collectionViews.buttons["Friday, November 25"].tap()
// 3. Dismiss the DatePicker popup
application.datePickers["DatePicker"].tap()
}
This test works on iOS 14 and iOS 15 devices. Sadly, the final application.datePickers["DatePicker"].tap()
call is failing on iOS 16 devices because application.datePickers["DatePicker"]
is not hittable. How do I dismiss the DatePicker popup on iOS 16 devices?
For what it's worth, I'm running the test via Xcode 14.1 on iOS 16.1 simulator devices. I do not have a real iOS 16 device to hand so I cannot verify the behaviour on a real iOS 16 device.
Lastly, you can find a minimal application project that demonstrates the problem here.