How to open a second browser without closing the first?

When I attempt to open a second browser, the browser opened first is closed, without there being a close browser command. For example…

WebUI.openBrowser(‘’)

WebUI.navigateToUrl(‘https://www.google.co.uk/’)

WebUI.openBrowser(‘’)

WebUI.navigateToUrl(‘https://www.google.co.uk/’)

…results in only one browser open at the end of the test.

Is this deliberate behaviour, or perhaps a defect? Is there any way to be able to open two concurrent browsers, does anyone know please? I need a second browser open to perform an action that will affect the outcome of the session in the first browser.

Thanks :slight_smile:

Kevin

Hi Kevin,

you can open two WebDrivers manually and switch between them. Drivers are located in Katalon installation folder - configuration\resources\drivers

System.setProperty("webdriver.chrome.driver","C:\\path\\to\\chromedriver.exe")
System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe")
WebDriver chrome = new ChromeDriver()
WebDriver ff = new FirefoxDriver()
// let Katalon know that chrome driver is usedDriverFactory.changeWebDriver(chrome)// Katalon keywords work as usual
WebUI.navigateToUrl("www.chrome.com")// now you can switch to FF driver
DriverFactory.changeWebDriver(ff)
WebUI.navigateToUrl("www.firefox.com")
4 Likes

Thank you Marek, that looks very interesting, I’ll give that a try.

Thinking ahead, how will this work when I eventually end up running my tests in a Test Suite Collection, for a variety of browsers?

And do you know why Katalon closes the browser currently without a close browser commmand? Is this expected/desired behaviour?

Thanks,
Kevin

When you end your work, just call close() on both/all drivers - it terminates them.

Regarding closing browser after test case - I think it is desired behavior of Katalon, but don’t know why. Maybe some kind of resource protection, if you forget to terminate driver, you can run out of HW resources after few tests.

If anyone is having a hard time finding which import statements are needed to get the above code to work, the following should do:

import org.openqa.selenium.WebDriver as WebDriver
import org.openqa.selenium.firefox.FirefoxDriver as FirefoxDriver
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import org.openqa.selenium.chrome.ChromeDriver as ChromeDriver

On macOS, drivers can be found in the following directory:

/Applications/Katalon Studio.app/Contents/Eclipse/configuration/resources/drivers/firefox_mac/geckodriver

2 Likes

What is the folder path for katalon inside docker?

Kevin, Did you ever figure out a good approach for opening and using multiple browsers across test cases within a test suite?

Hi, I’m afraid I didn’t find a good solution, I just worked-around this issue by re-opening a browser when required (I still don’t know if the closing of browser 1 when browser 2 is opened is for technical reasons, or a defect, or something else).

I’ve found this works well for me guys
def currentWindow = WebUI.getWindowIndex()

	WebUI.executeJavaScript('window.open();', [])

	WebUI.switchToWindowIndex(currentWindow + 1)

	WebUI.navigateToUrl('www.google.com')

	WebUI.waitForPageLoad(5)

             Do some other actions here  ....

	WebUI.switchToWindowIndex(currentWindow)