Failure Timer

So I’ve tried WebUI.delay() already, and I’ve also changed in my project settings for the timer to be 5 seconds, but I’m having a strange issue that I can’t find a work around to.

I have a code written for if the program can’t change the window index, then it needs to go back instead of closing the window. When the program clicks an ad that navigates to a new url instead of opening a tab to a new url, it hangs on this part of the code for the full 30 seconds instead of just 5 seconds, and then continues the way it should. So my code works properly, that’s fine, and I have tried many other ways, but this is the only way it works, and my only problem is the timer for 30 instead of 5. Can anybody help me figure out what to change?

WebUI.click(findTestObject(Ad))
WebUI.switchToWindowIndex(1, FailureHandling.OPTIONAL)
if (WebUI.getWindowIndex() == 1) {
url = WebUI.getUrl()
WebUI.closeWindowIndex(1)
WebUI.switchToWindowIndex(0)
CustomKeywords.‘adStat.Home.home’(url)
} else {
url = WebUI.getUrl()
WebUI.back()
CustomKeywords.‘adStat.Home.home’(url)
}
}

Clicks ad; switches to window 1; if it can, it grabs the url and close the tab; if not, it’ll grab the url and go back

I have it written this way for the mannerisms of Katalon as well. I need the switch Window Index to be optional for this to work properly.

Any help is appreciate!

I’ve no idea what the issue is there… very strange. What I would do is add comments to see which comment takes the 30 secs to appear:

WebUI.comment("Click Ad")
WebUI.click(findTestObject(Ad))
WebUI.comment("Attempting switch...")
WebUI.switchToWindowIndex(1, FailureHandling.OPTIONAL)
WebUI.comment("Switched!")
if (WebUI.getWindowIndex() == 1) {
  WebUI.comment("Inside IF")
  url = WebUI.getUrl()
  WebUI.closeWindowIndex(1)
  WebUI.switchToWindowIndex(0)
  CustomKeywords.'adStat.Home.home'(url)
} else {
  WebUI.comment("Inside ELSE")
  url = WebUI.getUrl()
  WebUI.back()
  CustomKeywords.'adStat.Home.home'(url)}

My guess is, something unexpected is causing the delay (perhaps the call to switchWindowIndex?)

Hope that helps you find it.

It takes a while to comment “Switched!” So it is the WindowIndex(1) it’s hanging on, because it’s looking for something that doesn’t exist. It’s the only way I can test it though. Is there no other way to change the time for that? I can deal with it if not, but that stinks that it stays there for so long

I’m sure there is a way – but I don’t think there’s a way in Katalon APIs (but I could be wrong). Perhaps this StackOverflow answer might help? https://stackoverflow.com/a/38101416

If you end up wrapping this in a Keyword, be sure to post back the answer so others might benefit - thanks.

So for a work around, I tried doing it by title, thinking maybe that’s the next best thing to track it by. So here’s the code:

WebUI.openBrowser(‘websitehere’)

title=WebUI.getWindowTitle()

WebUI.click(findTestObject(AdNo))

if(WebUI.getWindowTitle(title)){

WebUI.switchToWindowIndex(1)

url=WebUI.getUrl()

WebUI.switchToWindowIndex(0)

WebUI.closeWindowIndex(1)

CustomKeywords.‘adStat.Home.home’(url)

}else{

url=WebUI.getUrl()

WebUI.back()

CustomKeywords.‘adStat.Home.home’(url)

}

but it gives me this error:

Test Cases/Samples/Check window Index FAILED because (of) groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.getWindowTitle() is applicable for argument types: (java.lang.String) values: [Creative COW - Tutorials and Articles]

Possible solutions: getWindowTitle(), getWindowTitle(com.kms.katalon.core.model.FailureHandling), getWindowIndex(), closeWindowTitle(java.lang.String)

I tried something similar using index instead of title, but got a similar error. Is it not saving the variable ‘title’ properly?

String title = WebUI.getWindowTitle()
...
if(WebUI.getWindowTitle() == title)

I haven’t looked at the rest of your logic, but that stuck out as a problem.

1 Like

For anybody trying to do something similar, use WebUI.getWindowTitle() as a work around. It’s a few extra steps, but it’s better than waiting 30 seconds for one step

Here is the functional code:

WebUI.openBrowser(‘website’)

title = WebUI.getWindowTitle()

WebUI.click(findTestObject(AdNo))

if (WebUI.getWindowTitle()==title) {

WebUI.switchToWindowIndex(1)



url = WebUI.getUrl()



WebUI.switchToWindowIndex(0)



WebUI.closeWindowIndex(1)



CustomKeywords.'adStat.Home.home'(url)

} else {

url = WebUI.getUrl()



WebUI.back()



CustomKeywords.'adStat.Home.home'(url)

}