I am trying to create a simple if else statement but not sure I understand the tools flow.
Id like to validate I set the username field to say “LoginName” as the text, then check if the text isn’t what is expected to set it to “Username” else to change it to simply “Name”…
Can someone point me in the right direction? Thanks…
if (WebUI.verifyNotMatch(WebUI.getAttribute(findTO(input_Sign On_userName), “value”), “UserName”, false)) {
// if did not match
} else {
// it did match
}
The verifyNotMatch returns a boolean which makes a good “condition” for the if statement. I used getAttribute but the statement could be getText based upon the element.
You have to ensure the code is properly formed: use simple quotes (that don’t have curves), properly placed parenthesis, etc. I copied my text into KS, fixed it up and have put it again below:
if (WebUI.verifyNotMatch(WebUI.getAttribute(findTestObject(‘input_Sign On_userName’), ‘value’), ‘UserName’, false)) {
WebUI.comment(“if did not match”)
} else {
WebUI.comment(“it did match”)
}
Unable to get attribute (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to get attribute
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
Are you familiar with Inspecting the element’s code to see if there are attributes or just text? Right click on the page beside the element and select Inspect. You may have to do this twice to have the code pop to the specific element.
Check if the input_Sign On_userName element has a “value” attribute with any text. If there is no “value” attribute, but the text shows, then change getAttribute to getText and adjust the rest of the statement like deleting the “value” part.
You could also copy and paste the input_Sign On_userName from elsewhere and replace the one in the code I gave to ensure it is spelled correctly, (especially the path structure to the element), like below:
if (WebUI.verifyNotMatch(WebUI.getAttribute(findTestObject(‘Page_e3 - Login/input_Sign On_userName’), ‘value’), ‘UserName’, false)) {
groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.getText() is applicable for argument types: (null, java.lang.String) values: [null, text]
I can only now ever get this to return a value of 1 since adjusting the code regardless of if the username values match or not. It appears there is a real struggle to see the value within the input and after following suggestions I cannot get this to work…
In the if() statement you will notice your are using WebUI.getText(). You might expect that getText() allows you to “read” a value and setText() will allow you write a value -
unfortunately, that is not true.
You need WebUI.getAttribute()
Further, I think you need to manage Failure Handling, and pass FailureHandling.OPTIONAL to WebUI.verifyNotMatch()
Going based off of the help desk comment it appeared get attribute wasn’t going to work, I’ll adjust the code again but it seems like the keyword elements for something like this aren’t helpful.