A way to pass a while statement that it designed to fail

Hello,

This may be an odd situation/request I’m trying to figure out here. I have a while statement that loops through and adds records until an allotment is met and then continues on to other things. Is there a way to make it so the while statement does not show as failed in the reports/logs?

The while statement of course is designed to fail but technically this is not a failed test as I’m trying to just fill the allotment and then continue. I would use a for statement but the allotment number is not always the same.

I have tried various ways of failure handling but I haven’t made any discoveries on it. My first assumption is that this cannot be done since a while statement will always fail (unless you have an infinite loop).

I’ll post my sample while statement code below:

while (exhibitor_reg == true) {
if(reg_number == 5){
break
}
    try {
        WebUI.verifyElementPresent(findTestObject('IECS0618 EX Objects/input_btnAddEditEX'), 1, FailureHandling.OPTIONAL)
        WebUI.click(findTestObject('IECS0618 EX Objects/input_btnAddEditEX'))
        WebUI.delay(1)
        WebUI.click(findTestObject('IECS0618 EX Objects/input_btnContinue'))
        if (WebUI.verifyElementPresent(findTestObject('IECS0618 EX Objects/div_You missed 4 field(s). The'), 0)) {
            WebUI.comment('Validation is working')
        } else {
            WebUI.comment('Validation has failed')
            return null
        }
        
        WebUI.setText(findTestObject('IECS0618 EX Objects/input_FirstName'), 'testrecord')
        WebUI.setText(findTestObject('IECS0618 EX Objects/input_LastName'), 'testrecord')
        WebUI.setText(findTestObject('IECS0618 EX Objects/input_Phone'), '9876543210')
        WebUI.setText(findTestObject('IECS0618 EX Objects/input_Email'), 'testrecord@cdsreg.com')
        WebUI.click(findTestObject('IECS0618 EX Objects/input_btnContinue'))
reg_number++
    }
    catch (Exception e) {
        //exhibitor_reg = false
break
    } 
}

Any info or help on this is much appreciated,

Going to follow up with this,

I was able to actually get this to work, using the optional failure handling makes the test case show as passed when generating a report. If you are uploading to Katalon Analytics however, the test case will show as failed anyway.

Hi Tyler

Sorry, I missed your original post, I’d like to know more. Can you strip down the code a little? Which line(s) causes the exception to trigger?

And by the way, you’re not the first person to notice there’s a difference in the reporting between suites and analytics.

Hey @Russ Thomas,

The line below is what will cause the exception to happen. The add EX button will disappear once allotment has been met and it gets replaced with a buy over allotment button. In this case the script will be looking for the add button, which it won’t find it, and then after the exception happens it then breaks out of the while and continues to purchase an over allotment item.

Out of curiosity as well, are there any other differences that I have not noticed yet between the exported reports and Katalon Analytics?

WebUI.verifyElementPresent(findTestObject('IECS0618 EX Objects/input_btnAddEditEX'), 1, FailureHandling.OPTIONAL)

Thanks for the clarification, Tyler.

I don’t know of any, but that particular issue has been raised before. I’ve yet to try KA myself (don’t ask me why I’m deemed an “expert” - complete mystery to me).

if (WebUI.verifyElementPresent(findTestObject(‘Object Repository/New Folder/Page_Your store. Wishlist/input_245.00_updatecart’),
5) == true) {
while (WebUI.verifyElementPresent(findTestObject(‘New Folder/Page_Your store. Wishlist/h1_Wishlist’), 5) == true) {
WebUI.click(findTestObject(‘Object Repository/New Folder/Page_Your store. Wishlist/input_Remove_removefromcart’))

    WebUI.click(findTestObject('Object Repository/New Folder/Page\_Your store. Wishlist/input\_245.00_updatecart'))  
}  
  
WebUI.verifyTextPresent('The wishlist is empty!', false)  

} else {
}

first time it successfully run till the 1st while but 2nd time again it will go to find the while and fails the test case i am not getting how it will break and stop the while condition