Reputation: 203
Since I need to write unit tests for our project, does anyone do this before? How to test the universal link by codes?
Upvotes: 1
Views: 1960
Reputation: 1187
Actually I found a really cool example how to do this here:
https://blog.branch.io/ui-testing-universal-links-in-xcode-9/
Basically it opens the iMessage app in the simulator, sends a message containing the link to one of the simulator's contacts, then taps on the link within the message app.
You can then assert whether your app was opened or if the correct view was opened depending on what you want your universal link to do within your app.
Upvotes: 2
Reputation: 2514
You can use XCUITest to test full interaction: open Safari; load page with your link; tap on link; ensure your App is opened; ensure your App is handled Universal Link properly. This is not an easy setup. And generally driving Apps you not control (like Safari) is not a documented feature of XCUITest. Can use this https://github.com/facebook/WebDriverAgent as a reference. It does uses XCUITest under the hood.
Upvotes: 0
Reputation: 2828
Unfortunately, there is no way to open a Universal Link programmatically. Apple only allows Universal Links to be opened with user intention. That means calling openURL:
will open the link in Safari.
I would suggest mimicking the same response to a Universal Link by programmatically calling application:continueUserActivity:restorationHandler:
. This is the function called by universal links and can be triggered programmatically. You'll just have to ensure that the passed off user activity has all of the same information that your universal links activity would have. Hope that helps!
Upvotes: 2