Opening Safari while running iOS app

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. :slightly_frowning_face:

Why is that happening? Any suggestion how to solve this?

driver.activateApp("com.apple.mobilesafari");

now continue as usual in test code. tap -> enter url -> confirm

  1. there is button with name ‘URL’ tap on it.
  2. 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).

1 Like

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! :slight_smile:

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