Reputation: 2882
I'd like to write a test for my iOS app that verifies the correct screen content is shown when the app is launched from a custom registered URL scheme.
For example, a user receives an email with a link to myapp://action1/1234
. When they tap on this link, my app is launched and the screen displays "1234".
In didFinishLaunchingWithOptions
my AppDelegate checks to see if launchOptions?[UIApplicationLaunchOptionsURLKey]
exists and takes appropriate action.
How do I write a UI test so that the app launchOptions dictionary contains the expected URL when the app is launched?
Upvotes: 5
Views: 2225
Reputation: 81
You can make this work by leveraging launchEnvironment
on XCUIApplication
in combination with a few lines of custom code in your target app. Basically you would set a custom launch environment variable for this test, and in your app you would check for that variable and handle it the same way you would handle the existence of the particular UIApplicationLaunchOptionsURLKey
you're expecting.
In your app you can check that value via NSProcessInfo.processInfo.environment
which returns a dictionary of the environment variables.
(Take note that the default XCTestCase template in Xcode 7 includes a call to XCUIApplication -launch
in setup
which will terminate any previously running instance, and launch a new instance by default.)
Edit: wanted to add, I've written a little bit more about this in an article on Xcode 7 UI Testing Tips, in case it's helpful.
Upvotes: 1