Determine if browser opened with getWindowTitle()

I would like to open a browser only if an older one is not already launched.

I tried to use getWindowTitle() function in order to catch BrowserNotOpenedException if browser were not launched.
Unfortunately, Katalon never goes in catch block although my console display this exception :
Caused by: com.kms.katalon.core.webui.exception.BrowserNotOpenedException: Browser is not opened

String titre=’’
// launch browser if not open
try {
titre = WebUI.getWindowTitle(FailureHandling.OPTIONAL)
} catch (com.kms.katalon.core.webui.exception.BrowserNotOpenedException e) {
println “no browser open !”
} catch (Exception e) {
println “other exception” + e

Do you see what to add in order to go into catch blocks ?


You need to allow the exception to fall through to your catch.

Try removing your FailureHandling.OPTIONAL argument from getWindowTitle(), and have your catch block catch a StepFailedException instead (or just have it catch any Exception).

try {
  String title = WebUI.getWindowTitle(FailureHandling.STOP_ON_FAILURE)
} catch(Exception e) {
  WebUI.comment 'The exception was caught...'
  WebUI.comment e.message

WebUI.comment 'After catch'

hello everyone, thank you for your fast answers !
Unfortunately, neither FailureHandling.STOP_ON_FAILURE or FailureHandling.CONTINUE did solve my problem :frowning:
After executing this code, I never have any println from both catch blocks (BrowserNotOpenedException nor Exception)

I finally dealed with this problem by testing if variable titre == null (=> then I know that browser has not been launched)
But I do not like this code and I would have prefer to understand why ! :grimacing:

I you have other idea, I will try last week

have a good WE

In fact, your solutions were OK.
Sorry, hour is too late for me, I am not on TOP :sleeping:

So yes, I had to use FailureHandling.STOP_ON_FAILURE
And block catch has to be on Exception as it is throwing a StepFailedException

final working code :

String titre=’’
// lancement du browser si pas encore ouvert
try {
titre = WebUI.getWindowTitle(FailureHandling.STOP_ON_FAILURE)
} catch (Exception e) {
if (e.toString().contains(“Unable to get the title of the current window”)) {

Thank you !

Which I actually find strange. I gave you that code because I tried it and found it worked. I would have expected the STOP_ON_FAILURE to have immediately halted the TC execution.

Having seen @Brandon_Hein’s proposal, I’d have thought that would be a better approach (but I haven’t tested it).

Well STOP_ON_FAILURE is the default behavior if no arg is provided, so I would expect the same result honestly.