I would like to create several tests for native iOS application. To be more precise, I want to test deep links. But I am not sure how to trigger deep link with XCUITest and I don't really see how launch()
and launcArguments
(https://developer.apple.com/documentation/xctest/xcuiapplication) can help me. Did anybody have a chance to open deep link with XCUITest?

- 3,699
- 5
- 37
- 67
-
What do you mean by a deep link? Please provide info. – ablarg Sep 04 '18 at 21:00
-
@ablarg I meant to say "universal link" (https://developer.apple.com/videos/play/wwdc2015/509/). Sorry for confusion, I used the word "deep" because this is how it's named in android world :) – olyv Sep 05 '18 at 08:35
4 Answers
In iOS 14 using Spotlight seems to work well:
private func open(_ urlString: String) {
XCUIDevice.shared.press(.home)
XCUIApplication(bundleIdentifier: "com.apple.springboard").swipeDown()
let spotlight = XCUIApplication(bundleIdentifier: "com.apple.Spotlight")
spotlight.textFields["SpotlightSearchField"].typeText(urlString)
spotlight.buttons["Go"].tap()
}

- 6,116
- 7
- 48
- 77

- 441
- 1
- 4
- 8
I never tried this, but this idea comes to my mind. Create a new dummy project/application that should only contain some links pointing to URLs that you expect your original app to open. From that new application, write some UI tests that tap a link, like this:
func testOpeningLinks() {
let app = XCUIApplication()
app.links["Some link text"].tap()
// This is the place where your original app should be opened...
// Find the XCUIApplication object:
let originalApp = XCUIApplication(bundleIdentifier: "original.app.bundle.identifier")
// You should be able to find some views from original app from here, eg. a button:
let button = originalApp.buttons.element
}
This would work only if you have previously installed your app on the device/simulator where you're running your UI tests.

- 2,070
- 1
- 21
- 37
Set safari as app like this
let safari = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari")
Open your email in safari
- Tap on the link
- Normally assert some element on app

- 60
- 6
-
thanks for suggestion. That's exactly where I ended up. Unfortunately, there seems to be no other way to it in XCUITest at the moment :( – olyv Oct 08 '18 at 12:40
As of iOS 16.4, macOS 13.3, and Xcode 14.3, new XCTest UI Testing API's are available which let you do this in an even easier way.
You can open your application with a specific URL: https://developer.apple.com/documentation/xctest/xcuiapplication/4108226-open
Or, open any URL in the default application for it: https://developer.apple.com/documentation/xctest/xcuisystem/4108234-open

- 121
- 2