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

3 Likes

it doesn’t work for me for any of the arguments “-u” and “-U”, any ideas?

appium log: “Cannot request the screen point at NSPoint:”

do you know what other arguments can be passed to open safari in new tab appium?

This -u and -U made all the difference between ‘not able to run’ and able to run. Thank you for sharing :slight_smile:

I am still facing issues in this. I have used the above code and still, the link opens up in the browser. i am using Appium version1.22.

public void Deeplink(String Link ) {
String deepLinkURL = Link;

	((RemoteWebDriver) 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<String, Object>();
	params.put("bundleId", "com.apple.mobilesafari");
	params.put("arguments", args);

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

	//driver.findElementByAccessibilityId("Open").click();
}

Any help will be highly appreciated

I use direct enter in browser url.

  1. Open Safari
  2. Enter into url input deep link value

That is not working. It must open with the application

It is working for me 2+ years.

Also to read https://appiumpro.com/editions/84-reliably-opening-deep-links-across-platforms-and-devices

Thank you, Aleksei for your quick responses. I followed the link you shared and now it is working for me.
I appreciate your support.