Open a deep link via browser in an already-open application -Solved

Hi, all,

Here’s what I’m trying to accomplish (mobile, Android, Katalon Studio version 6.3.0):

  1. Open MyApp, navigate to a certain page there.
  2. Launch a browser window to a list of deep link URLs.
  3. Tap a URL that will open the existing instance of MyApp (opened in Step 1) to a certain page.

However, every time I tap the URL in the browser, it re-opens MyApp, reloading it to the launch screen rather than using the instance that was opened in Step 1. This test works manually so it’s not the link itself forcing MyApp to reload.

I’ve read that using WebUI.openBrowser will kill all other open browsers, but does that also extend to other open applications that aren’t browser windows? I’m guessing when the browser opens it kills the already-open MyApp.

Any suggestions here would be greatly appreciated. Thanks for reading.

Things I’ve tried:

  1. Opening the browser first, then opening MyApp, and then trying to switch back to the browser in a couple of ways: using Window Index and Window Handle.

    //Open browser first
    WebUI.openBrowser()

    chromeWin = WebUI.getWindowIndex()
    //Alternately
    _ /AppiumDriver driver = MobileDriverFactory.getDriver()_
    _ chromeWin = driver.getWindowHandle()
    /_

    //Start MyApp
    WebUI.callTestCase(findTestCase(‘Macros/Start Application’), [(‘SplashScreen’) : false, (‘LocationPrompt’) : false], FailureHandling.STOP_ON_FAILURE)

    Mobile.tap(Finder.findButton(‘Search’.concat(GlobalVariable.G_Object_Lang)), GlobalVariable.G_Timeout)

    Mobile.setText(Finder.findTextField(‘EnterAddress’), ‘Toronto’, GlobalVariable.G_ShortTimeOut)

    Mobile.tap(Finder.findTextField(‘SearchResult_Toronto’), GlobalVariable.G_ShortTimeOut)

    //Return to browser
    WebUI.switchToWindowIndex(chromeWin)
    //Alternately:
    /*driver.switchTo().window(chromeWin)
    _ DriverFactory.changeWebDriver(driver)*/ _

    WebUI.navigateToUrl()

    Mobile.scrollToText(findTestData(‘Deep Links Text’).getValue(‘Sharing Systems’, 2))

    WebUI.click(Finder.findLink(‘TorontoSignUp’))

    //Switch to app context in order to work with app opened by deep link
    AppiumDriver driver3 = DriverFactory.getWebDriver()

    driver3.context(“NATIVE_APP”)

    Mobile.delay(10)

    Mobile.verifyElementExist(Finder.findAlert(‘Toronto_Badge’), GlobalVariable.G_MedTimeOut)

Neither of these approaches return to the browser window at the specified step–no errors thrown. Both perform the scrollToText inside MyApp, obviously can’t find the link there, and fail. I expect I’m missing something about switching between the app and browser but not sure what it is.

  1. Opening the browser as an existing application to avoid using WebUI.openBrowser keyword.

    //Open MyApp
    WebUI.callTestCase(findTestCase(‘Macros/Start Application’), [(‘SplashScreen’) : false, (‘LocationPrompt’) : false], FailureHandling.STOP_ON_FAILURE)

    Mobile.tap(Finder.findButton(‘Search’.concat(GlobalVariable.G_Object_Lang)), GlobalVariable.G_Timeout)

    Mobile.setText(Finder.findTextField(‘EnterAddress’), ‘Toronto’, GlobalVariable.G_ShortTimeOut)

    Mobile.tap(Finder.findTextField(‘SearchResult_Toronto’), GlobalVariable.G_ShortTimeOut)

    //Return to browser window
    RunConfiguration.setMobileDriverPreferencesProperty(“appPackage”, ‘com.android.chrome’)
    RunConfiguration.setMobileDriverPreferencesProperty(“appActivity”, ‘com.google.android.apps.chrome.Main’)
    RunConfiguration.setMobileDriverPreferencesProperty(“appWaitPackage”, ‘com.android.chrome’)

    Mobile.startExistingApplication(‘com.android.chrome’)

    AppiumDriver driver2 = MobileDriverFactory.getDriver()

    driver2.get()

    DriverFactory.changeWebDriver(driver2)

    Mobile.scrollToText(findTestData(‘Deep Links Text’).getValue(‘Sharing Systems’, 2))

    WebUI.click(Finder.findLink(‘TorontoSignUp’))

In that case, I get the error below. Increasing the timeout as it specifies does not help; I searched for further information about the error or how to fix it but came up empty.

Test Cases/Deep Links/App Open/OpenAndNavigate/Toronto Bike Share Sign Up - Copy FAILED.
Reason:
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Error attempting to start URI. Original error: Error: Error executing adbExec. Original error: ‘Command ‘/Users/stephaniesmith/.katalon/tools/android_sdk/platform-tools/adb -P 5037 -s f2979388 shell am start -W -a android.intent.action.VIEW -d https://mytesturl.com/deep-links com.android.chrome’ timed out after 20000ms’. Try to increase the 20000ms adb execution timeout represented by ‘adbExecTimeout’ capability

  1. Finally, I did try creating a Test Suite Collection and attempting to run the two applications in parallel on a single device but that is way too fidgety and difficult to time between the necessary steps.

Solved this by putting the link to the webpage in notepad, then doing the following:

  1. Open MyApp and navigate to the page I need.
  2. Open Notepad app (which doesn’t kill MyApp when it opens the way the browser does) and tap the link in the notepad that opens the browser page I need.
  3. Browser opens and I can scroll to the deep link URL needed, tap it, and it opens in the existing instance of MyApp.

A little convoluted, but it works.

1 Like