Automating deeplinks with iOS real device

Hi everyone, wasn’t sure where to put this but maybe someone will find it useful.

On a real device it is not possible to simply call driver.get(“url”), doing so will open SIRI and query with “url” often resulting in a search. Instead we can take advantage of Safari’s launch parameters and pass deep link URL as argument.

Below is sample code in Java:

String deepLinkURL = "deeplink://";
//it is necessary to first kill safari 
driver.executeScript("mobile: terminateApp", ImmutableMap.of("bundleId", "com.apple.mobilesafari"));

List args = new ArrayList();
args.add("-u");
args.add(deepLinkURL);

Map<String, Object> params = new HashMap<>();
params.put("bundleId", "com.apple.mobilesafari");
params.put("arguments", args);

driver().executeScript("mobile: launchApp", params);

driver.findElementByAccessibilityId("Open").click();
2 Likes

Just a small, but important update to the previous comment.
Key arg “-u” is valid until iOS 12.2.

If you would like you tests be executable on 12.3 and up, replace it with "–U"