Hi
my scenario is like this: I want to test universal links, which is a bit different than deeplinks. I want to test that when I tap on a specific universal link, proper screen is displayed in the app.
I was thinking a bit and probably best way to do this is to expose a website containing those universal links and during the test, I want to open Safari, navigate to website and then tap on a specific universal link to open in app.
My code to open Safari is like this:
private void openSafariURL(String URL) {
List args = new ArrayList();
args.add(ā-Uā);
args.add(URL);
Map<String, Object> params = new HashMap<>();
params.put(ābundleIdā, ācom.apple.mobilesafariā);
params.put(āargumentsā, args);
driver.executeScript(āmobile: launchAppā, params);
}
Now, all is good above ā First, I open the app and then I run this script above and Safari gets opened in the proper website, but the problem is that website remains open for 3 - 5 seconds, then it gets automatically closed (like closing the tab) and I end up on the blank page of Safari. 
Why is that happening? Any suggestion how to solve this?
1 Like
driver.activateApp("com.apple.mobilesafari");
now continue as usual in test code. tap -> enter url -> confirm
- there is button with name āURLā tap on it.
- now appears text field with same āURLā name where you enter url needed and tap last keyboard button.
code with actions above in our projects looks (removed Allure and logs):
public BrowserPage setURLInput(String urlTxt) {
Assert.assertTrue(tap(urlInputButton), createAssertionLog("Tap 'urlInputButton' FAILED"));
// clear url for sure (old url appears often on browser start)
setLookTiming(1);
tap(urlClearButton);
setDefaultTiming();
Assert.assertTrue(setValueHideKeyboard(urlInput, urlTxt), createAssertionLog("FAILED"));
return this;
}
all is left for you is specify: urlInputButton + urlClearButton + urlInput + setValueHideKeyboard + tap (your code also).
2 Likes
Apple has removed the support of -U command line argument from Safari, so there is no direct way to run the process with the given url set, at least on real devices
1 Like
@Aleksei, @mykola-mokhnach thank you for your responses.
I have solved it at the end by removing the -U and just open the Safari, tap on URL and enter the String myself. I thought it would be less stable, but it works ok! 
private void openSafariURL(String URL) {
List args = new ArrayList();
Map<String, Object> params = new HashMap<>();
params.put(ābundleIdā, ācom.apple.mobilesafariā);
params.put(āargumentsā, args);
driver.executeScript(āmobile: terminateAppā, params);
waitTime(2000);
driver.executeScript(āmobile: launchAppā, params);
if (isElementPresent(driver, By.id(āURLā))) {
driver.findElement(By.id(āURLā)).click();
waitTime(800);
driver.switchTo().activeElement().sendKeys(Keys.DELETE);
driver.switchTo().activeElement().sendKeys(URL);
waitTime(400);
driver.switchTo().activeElement().sendKeys(Keys.ENTER);
} else {
Assert.fail("Something went wrong - URL field not found! ");
}
}
However, for running deeplink tests on iOS 14, we are still using -U to directly push URL into Safari. Do you know when they have removed the support for this?
No idea. I donāt work for Apple