I am new into Katalon and trying to understand if and else or any other conditional logic.
I am using sample katalon website CURA Healthcare Service
and trying to inspest element for invalid username and password and Valid username and password.
I am trying to do following
Enter invalid username and password, Find element(error) is there.
Enter valid username and password, Check if the element is there after log in
WebUI.setText(findTestObject(‘Page_CURA Healthcare Service (2)/input_username’), demo_usn)
WebUI.setText(findTestObject(‘Page_CURA Healthcare Service (2)/input_password’), demo_pwd)
WebUI.click(findTestObject(‘Login Page of Demo Application/button_Login’))
if (WebUI.verifyElementPresent(findTestObject(‘Page_CURA Healthcare Service (3)/p_Login failed Please ensure t’)) == true) {
I think you don’t need any “if” and “else” in order to accomplish what you want to do.
// enter invalid username and passwordWebUI.setText(findTestObject('Page_CURA Healthcare Service (2)/input_username'), demo_usn)
WebUI.setText(findTestObject('Page_CURA Healthcare Service (2)/input_password'), demo_pwd)// try to login but...
WebUI.click(findTestObject('Login Page of Demo Application/button_Login'))// will fail
WebUI.verifyElementPresent( findTestObject('Page_CURA Healthcare Service (3)/p_Login failed Please ensure t'))// still you can try againWebUI.verifyElementPresent(findTestObject('Make Appointment Page/heading_Make Appointment'), 0)
// type valid username and passwordWebUI.setText(findTestObject('Page_CURA Healthcare Service (2)/input_username'), 'John Doe')
WebUI.setText(findTestObject('Page_CURA Healthcare Service (2)/input_password'), 'ThisIsNotAPassword')// life goes on ...
In my condition always if part executed, never goes to else and so ;when if condition fails program still search for elements in if condition and then fails obviously it wont find those elements on page -
below is my code-
"
String string_MatchRecords = WebUI.getText(findTestObject(‘Object Repository/Approce Application_GOAMTCH/total_records’))