Automating deeplinks with iOS real device


#1

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();