How EXACTLY WebUI.openBrowser('') and WebUI.closeBrowser() work? What is the logic and where is it documented?

Intuitively, and as per documantation,it should’ve been simple as this: openBrowser(‘’) - opens the browser, closeBrowser() - closes it.

Investigating an issue with running Katalon on Window agent on Jenkins with Katalon Plugin (there is no issue while running the same tests on Linux agent) Caused by: com.kms.katalon.core.webui.exception.BrowserNotOpenedException: Browser is not opened,

I’ve just learned that on my local Windows, it works like the following:

  1. If you open a browser in each test of the test suite and never use WebUI.closeBrowser() , still the broswer gets closed after each test

  2. If you have a test with just 1 line WebUI.closeBrowser(), the browser will be open and then closed

  3. If you have a test with just 2 lines

WebUI.openBrowser(‘’)
WebUI.openBrowser(‘’),

the browser will be a) opened b) closed c) opened

Question #1: Is all this expected and what else additional logic is used (if any)?

Question #2: If this is expected, where is this documented?

Question #3: If it’s not documented, then WHY is it NOT documented?

Opening and closing a browser is a time consuming operation, so it would be great to have some conrol over it. Is it possible to determine whether or not the browser is open?

  1. First check this setting to make sure you know what you’re doing that you may not realize you’re doing:

  1. Read the source if you think that’s going to help you.

Now post your question when you’re sure you know what’s going on.

Hint: This stuff is ancient and works as expected (for most people).

2 Likes

Thanks, @Russ_Thomas .

  1. The browser was opened and closed 3 times:

image

  1. If 2 is expected, then it’s great (though I doubt that it’s intuitively expected), still, why is that logic not documented? The “codeless” testing is a Katlalon sale point, not “documentless” testing and not the testing when an ability to understand someone’s enterprise code is a must.

Not correct.

The WebUI.openBrowser() checks if a browser window is already opened by a previous call of WebUI.openBrowser(). If yes it reuses the previous browser. It refrains from opening a new browser window. Consequently, using WebUI.openBrowser keyword, you can open only a single browser window. Regardless accidentally or intentionally, you will not open 2 or more browser windows by WebUI.openBrowser keyword.

This minute fact is not documented. I found this fact by my experiment and checked it is true at the source. See the source code LINE#242-243 of https://github.com/katalon-studio/katalon-studio-testing-framework/blob/master/Include/scripts/groovy/com/kms/katalon/core/webui/driver/DriverFactory.java

This behaviour is not equivalent to the 2nd Post-Execution Option: Terminate drivers after each Test Case.

This behaviour (WebUI.openBrowser opens does not open multiple browser windows) is good for usual cases; careless testers may forget calling WebUI.closeBrowsers(), and they may fall into a difficult situation. Therefore I think it is acceptable that this behaviour is NOT documented in detail.

1 Like

However if a Test Case script wants to open 2 browsers to test 2 different URLs simultaneously, Web.openBrowser blocks me. Therefore I once did an experiment in search for a practical solution. See

Thank you, @kazurayam.

I’m running the suite with multiple test cases and each of them has just one line WebUI.openBrowser(''). Visually it looks like the browser is opened and closed as many times as many test cases are included in the test suite. So, yes, as you wrote, I’ve never seen more than 1 browser open at the same time but , it looks (at least visually) like the previously opened browser (if any) gets closed and a new one gets opened every time and, if this is the case, it’s a waste of time and resources.

To the best of my knowledge, that’s what I see on Windows and it might be different on other OS. I started looking into it because there is an issue with running Katalon on Window agent on Jenkins with Katalon Plugin (there is no issue while running the same tests on Linux agent) Caused by: com.kms.katalon.core.webui.exception.BrowserNotOpenedException: Browser is not opened.

By the way, as an expert on Katalon, can you please explain witch Terminate drivers after each Test Suite would take preference

  1. the one in the settings (as in the screenshot above)

  2. the one in DemoTestListener (if uncommented out)

  3. the one in the test Suite (if it had WebUI.closeBrowser() and skipped = false)

I don’t think so. I think that a single WebDriver process is sustained and reused. But if you turn the option “Terminate drivers after each Test Case” ON, then yes the driver process will be terminated on end of each Test Cases (when a driver process terminates, it will close the browser window together).

I do not know.

Your question will only be answered by reading the source code of Katalon Studio itself; but it is not open-sourced. No user can know it.

And I do not think worth investigating; as 1, 2, 3 — in any case the driver process will be terminated.

1 Like