Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring If-else Statement in Katalon Studio

I'm trying to configure an if-else statement, but my code gets stuck on the if statement and doesn't go on to the else statement.

I've tried to add the break; to the if statement but it doesn't work, as well.

WebUI.openBrowser('')

WebUI.navigateToUrl('123/account/login?ReturnUrl=%2F')

WebUI.maximizeWindow()

WebUI.setText(findTestObject('123/Page_Log in/input_ _Username'), 'admin')

WebUI.setEncryptedText(findTestObject('123/Page_Log in/input_ _Password'), 'admin')

not_run: WebUI.verifyElementPresent(findTestObject('123/Page_Log in/span_Log in'), 1)

WebUI.click(findTestObject('123/Page_Log in/span_Log in'))

not_run: WebUI.verifyElementPresent(findTestObject('123/Page_Operator/button_To activate session sta'), 1)

WebUI.click(findTestObject('123/Page_Operator/button_To activate session sta'))

if (WebUI.verifyTextPresent("Operator already has active session", true)) {
    WebUI.click(findTestObject('if-else/Page_Operator/button_Clear'))

    WebUI.click(findTestObject('if-else/Page_Operator/button_To activate session sta'))

    WebUI.waitForPageLoad(5)

    WebUI.click(findTestObject('123/Page_Operator/click_phone'))

    WebDriver driver = DriverFactory.getWebDriver()

    WebElement Table = driver.findElement(By.xpath('//div[@id=\'missedCallsContainer\']'))

    List<WebElement> rows_table = Table.findElements(By.xpath('//tr[@class=\'dl-menu\']'))

    int rows_count = rows_table.size()

    println('No. of rows: ' + rows_count)
} 

else {
    WebUI.click(findTestObject('123/Page_Operator/click_phone'))
}

It works if the code goes in if statement but if that text that I have provided in if statement doesn't present, it stops working and doesn't go to else.

like image 696
brithwulf Avatar asked Jan 31 '26 13:01

brithwulf


1 Answers

Your script is good, and I think you just need to change a bit at the if statement. For if statement, I think you need to use another version of verifyTextPresent as below with one more parameter FailureHandling.OPTIONAL

enter image description here

More information can be found at https://docs.katalon.com/katalon-studio/tutorials/how_to_check_element_status_in_conditional_statement.html

like image 106
Tony Bui Avatar answered Feb 03 '26 08:02

Tony Bui