Hi Community,
Need some help with in creating a Dynamic Wait in Katalon.
I need to wait for an element to appear in the UI.This element appears after making some date adjustment in the System.This can generate in 5 min or at times can even take 20 min to generate.
I need to check and validate if Highlighted Activity appears on the screen and keep waiting until the activity is generated.
For this,i tried using capturing the 1st activity message and used a For loop with an if statement to check if the expected activity appears or not. If not it will keep clicking on Account link on left navigation to refresh the page.
def Activity0 = WebUI.getText(findTestObject(âBilling/pge_AccountPage/lbl_ActivityDescriptionIndex0â))
for (int i = 0; i < 20; i++) {
if (Activity0.contains(âAutomaticâ)) {
WebUI.click(findTestObject(âBilling/pge_AccountPage/lnk_Accountâ))
WebUI.waitForPageLoad(20)
}
else {
WebUI.getText(findTestObject(âBilling/pge_AccountPage/lbl_ActivityDescriptionIndex0â))
}
The problem with this approach is, it runs the loop for 20 times and moves out.
I want it to wait until the activity appears and not proceed to next test case execution in a Test suite.
1 Like
You need your check for the element within the loop - currently you are setting the value for Activity0 in your first step shown, outside the loop - this never changes. Your âelseâ statement only gets the text, it doesnât change Activity0. You also need to look at variable naming standards, just a tip.
I would suggest you have âverifyElementPresentâ or verifyElementTextâ eg
for (int i = 0; i < 20; i++) {
if (WebUI.verifyElementText(findTestObject('Billing/pge_AccountPage/lbl_ActivityDescriptionIndex0'), 'Automatic', FailureHandling.OPTIONAL)) {
WebUI.click('your test object')
break
}
WebUI.delay(10)
}
Adjust the timings as required - the above wouldnât wait for 20 minutes but just needs some tweaks
Thanks @Dan_Bown for your inputs.
Is there any other approach that you would suggest if not this.
I was looking for something like Wait Until Element Exists but I couldnât find any such action in the default actions list.
I want it the script to wait ,pause and go no further until the element exists in the UI.
you could use such a wait but personally I prefer a loop. Just set your timeout to 1200 for 20 minutes as per @kazurayam 's doc above if you decide on that approach
Instead of a for loop, you could try a while loop. The issue is if the text does not show you would get an endless loop, so you should have two components of your while loop. One is the test for your text and the other is a test for a counter, like your for loop has.
Katalonâs wait* keywords internally uses the interval of 1 second. Not documented, but I seem to remember I found it in the source. Repeating prosessing with the delay of 1 seconds may consume higher CPU usage.
Day_Bown proposed the interval of 10 seconds. This would result less CPU usage than the wait* keywords. if @dsingh1 envisages 5minutes or longer timeout, then inteval could be set even longer.
I havenât examined the CPU% difference. Please examine it yourself.
Another option is to end your first Test Case after setting the text and start a second TC but you would have to change the first TC to save the expected name to a spreadsheet or external file and then read in the expected name in the second TC. You may have the same issue in that your time may still not have elapsed but maybe you can review some other part of the pages and come to this text at the endâŚ