Capturing Error message

Hi guys,

I just wanna ask, is it possible to verify the wording of error message like this

without capturing the object?

maybe on the FSD, the error message was clearly written like “Login failed! Please ensure the username and password are valid.”, but I’m not sure is there a typo or not

usually, I try to capture the object of the error message first and then try to using WebUI.verifymatch() like this:

String username = “John”
String password = “Password”
String Errormsg = “Login failed! Please ensure the username and password are valid.”

//Open browser
WebUI.openBrowser(‘https://katalon-demo-cura.herokuapp.com/’)

//Click option button
WebUI.click(findTestObject(‘Homepage/Option_btn’))

//Click login button
WebUI.click(findTestObject(‘Homepage/Login_btn’))

//Set the username and password
WebUI.setText(findTestObject(‘Login/Username_field’), username)

WebUI.setText(findTestObject(‘Login/Pass_field’), password)

//Click login button
WebUI.click(findTestObject(‘Login/Login_btn’))

//verify the error message is appear
if(WebUI.verifyElementPresent(findTestObject(‘Login/Err_msg’), 30)) {
KeywordUtil.markPassed(“Error message is appear”)
}else {
KeywordUtil.markFailed(“Error message does not appear”)
}

//verify the wording message
Errmsg_notif = WebUI.getText(findTestObject(‘Login/Err_msg’))
if(WebUI.verifyMatch(Errmsg_notif, Errormsg, false)) {
KeywordUtil.markPassed(“Wording is fine”)
}else {
KeywordUtil.markFailed(“There’s a typo”)
}

I don’t know if it will help but I just take a Screenshot of the page where I am testing to see if a message appears (and to ensure I have the full message). Then I review the screenshot after the test to check the text message if the test should fail. As an example, the test can fail due to me missing a period at the end of the message.

gReportPathway = ".\\Reports\\Screenshots\\RT 030 RPCS\\"

WebUI.takeScreenshot(gReportPathway + "msg1.png")

In my case, all the screenshots are stored in a top folder, called Screenshots, which is within the Reports folder of the Katalon project, then I let KS create a folder for each test suite; in the above case, RT 030 RPCS.

Yes, there is a way.

Firstly, in essence, there is nothing wrong with your test code. However…

If you are proposing to type that message into your test case and then compare it with what is found, you are merely waiting for a race condition to show up… one day.

For strings like this, you should parse in the same source that the devs use to build the site. If they’re just “typing it in” too, then you’re on a loser from the start. This method of comparing on-screen text simply doesn’t scale to thousands of messages/strings.