Following some of the recent answers, here is a working solution for SwiftUI that I am using to deep link into parts of the app for our UITests.
func launchDeepLink(with url: URL) {
addUIInterruptionMonitor(withDescription: "System Dialog") { (alert) -> Bool in
let button = alert.buttons.element(boundBy: 1)
if button.exists {
button.tap()
}
return true
}
if #available(iOS 16.4, *) {
XCUIDevice.shared.system.open(url)
}
}
It includes the functionality to confirm the alert view that will pop up. Only tested this in SwiftUI using the .onOpenURL view modifier.
Note that it is using the open call on XCUISystem not XCUIApplication as that causes the flakey experience some have mentioned.
Hope that helps :)
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags: