Is it possible to set the browser type directly in the katalon studio script?

Hi.
Currently, my default katalon browser is Chrome. So whenever I run a script I click the Run button and the script opens the Chrome browser and proceeds to web testing. If I wish to change the browser type I must manually select it in the Run button’s dropdown menu. I can also make custom browser types with profiles. But in both cases I must select them using the button/selection UI.

Is it possible to have katalon studio open different browser types directly through the code in the Script mode? For example, I use WebUI.openBrowser("") to open a browser, which ends up being Chrome which is the default, but can I write some code which tells that command to open in a different browser, like Firefox, and then go back and fourth in the script without ever having to click Run multiple times?

The following post seems to discuss this issue:

However, this referenced page is empty and has no directions. And this referenced page seems to describe a solution, but it is through the console mode, but I don’t use that, I only use script mode and click Run.

Thank you.
Ilya

This thread has some details…

Yes, it is possible. I have ever done similar programming. This involved a lot of work. It required me very careful Test-driven development using JUnit4 inside Katalon Studio. This is not as easy as you may expect.

The core part is com.kms.katalon.core.webui.driver.driver.DriverFactory#changeWebDriver(org.openqa.selenium.WebDriver)

What you need to do in your script.

  1. Create instance of org.openqa.selenium.WebDriver of the Browser type you want (Chrome, Headless Chrome, Firefox etc), this will open a new window which is not yet recognised by Katalon Studio
  2. call DriverFactory.changeWebDriver(yourWebDriverInstance), this makes Katalon Studio aware of the browser process you created and let KS to communicate with it when you call WebUI.* keywords.

You can keep multiple browser windows (Chrome and Firefox) open, and let Katalon Studio talk to either of them by calling DriverFactory.changeWebDriver(eitherOf2WebDriverInstances) back and forth.

But I wonder if you really want to do this complicated thing. May be not.

@Ilya_Novak

Do you want to run your test case multiple times while applying different browser types (Chrome, Firefox, Safari, Edge Chromium)?

If that is the case, Katalon Studio offers an alternative way of achieving it. Test Suite Collection can run a Test Suite with browser type you want. Very easy.

Are you aware of this feature?

I did not know about this feature, and it will be very useful in other cases, but for my current purposes I continue to need multiple browser windows open of different browser types.

However, opening the same browser type, but in incognito/private mode would do the trick. Is that possible as an alternative to a different browser type altogether?

Actually, I just posted a reply to this statement of mine, which I think will be useful to others.