Using WebUI keywords with list variable

Hello,
I’ve created a global variable called ArticleComponents and inside of it are two Test Objects.
Now in my test case i want to use a keyword ’ waitForElementPresent ’ and verify in that way if the elements given in the list are present on the site, might be a silly question but i couldn’t figure it out myself. Found something like this but is not working, is it possible to simply verify that all the elemnts given in this global list are present on the site?

WebUI.waitForElementPresent(GlobalVariable.ArticleComponents.get(1))

It is difficult for others to reproduce your case locally on their PC. Without reproducing your case locally, it is difficult for anyone to discuss about it.

Can you create a sample Katalon Studio project, zip it, and share it? The zip should contain all of:

  • the Test Object you defined
  • the Execution Profiles with Global Variable you defined
  • the Test Case you wrote

Okay my bad here for not putting timout at the and of the line, it works with

WebUI.waitForElementPresent(GlobalVariable.ArticleComponents.get(1), 0)

However Im still curious if its possible to verify the elements in the list in one go cause my code will start to look like this now :

Thanks for the answear, I will try to do that, you can have a look at my newest reply, maybe it is more clear to understand

GlobalVariable.ArticleComponents.each({ TestObject tObj ->
    WebUII.waitForElementPresent(tObj, 0)
})
1 Like

Works like a charm,thanks, I will try to read more about iteration methods, there is a mispeal in the WebUI part, should be like this:

GlobalVariable.ArticleComponents.each({ TestObject tObj ->
WebUI.waitForElementPresent(tObj, 0)
})

https://www.baeldung.com/groovy-lists#Iterating%20on%20a%20List

1 Like

Do you know how to make that if the element is not present to mark it as fail and stop the test?
Cause currently if that’s the case it just throws an error and marks the test as passed

Do you want to stop you test at all?

Then you should use WebUI.verifyElementPresent keyword.

WebUI.waitForElementPresent keyword is not designed to stop the test.

Or, if you stick to the waitForElementPresent keyword, you can write:

boolean found = WebUI.waitForElementPresent(tObj, 10)
if (!found) {
    KeywordUtil.markFailedAndStop("Disaster!")
}
1 Like

Ah yes WebUI.verifyElementPresent is good enough but thanks for the other one, might be usefull in the future :grin:

Just for your interest

Katalon Studio provides 2 built-in keywords WebUI.verifyElementPresent and WebUI.waitForELementPresent . What’s the difference?

See How to check element status in conditional statement? for the answere

Timeout of 0 seconds smells. Do you want it to do wait or not? I have no idea what 0 seconds timeout means. I have no idea what will happen if you specify -1 there.

Why not you specify 1?