I am using katalon 5.3.0 and chrome browser.
I need to verify the whether string contains a specific text.
I am searching for similar kind of contains function, which i used in selenium,
contains(test(),‘myWord’);
Can sombody tell how to verify text?
I had a similar query where I wanted to confirm an element started with some text and found I just need to put an asterisk on the end of the search text.
So in your case, if you are looking for something which contains myWord you could try *myWord* and see if that works.
In my Test Case I have following snippet:
WebUI.openBrowser(GlobalVariable.G_SiteURL)
def text = WebUI.getText(findTestObject('Page_CuraHomepage/btn_MakeAppointment'))
WebUI.verifyMatch(text, '^Make Appo.*', true, FailureHandling.STOP_ON_FAILURE)
see verifyMatch https://docs.katalon.com/display/KD/[Common]+Verify+Match
You could also use the Groovy contains function:
def text = WebUI.getText(findTestObject('your object'))
if (text.contains('myWord')) {
//your code here
}
Mate Mrse said:
You could also use the Groovy contains function:
def text = WebUI.getText(findTestObject('your object'))
if (text.contains(‘myWord’)) {
//your code here
}
I am using a very similar function, but an error message appears: Test Case FAILED because (of) Variable ‘contains’ is not defined for test case.
This is my function:
url= WebUI.getUrl()
if(url.contains.(‘print’)){
println(“hola”)
}
I don’t understand the reason of this, do you know what can I do to solve this? Thanks!
if(url.contains.('print'))
should be:
if(url.contains('print'))
(You have an extra ‘.’)
I can’t believe this, I had been watching the expression for a long time without realizing! Thanks so much!
Hi Team,
I am using the keyword Verify Text present on a page , where I need to find Text containing special character 'roundbraces () ’ Eg Task File 01 (TIF - Colour) , it does not detect the text because it has got round braces? can anyone help me with this?
Hi folks,
The following works for me but I am seeing a strikethrough on contains (see below) in Katalon’s Script view. Has anyone else seen this warning in Katalon?
def MyText = WebUI.getText(findTestObject(‘KatEx1/Page_CURA Healthcare Service/a_Make Appointment’))
if (MyText .contains(‘Make’)) {
println(‘MyText=’ + MyText)
Thanks,
Dave
Thanks for confirming my thoughts that contains is something that can be ignored.
Cheers,
Dave
You are welcome.
Yea ! best solved problem Groovy functions is more often better ty so much !!!
@Mate_Mrse the page is not available anymore… is there other info?
Yes, I have ever seen it. It is a bug of Eclipse. Please have a look at the following discussion.
It is the discussion Kazurayam posted just below your post (Groovy “Contains” function deprecated).
There is an easier way to assert text:
WebUI.verifyElementText((findTestObject(‘Your_Object’), ‘Expected_Text’’)
This will verify whole string; we have to find the partial text contains in a string.
example- find text ‘easier’ from string “There is an easier way to assert text:”
@ [kazurayam] solution provided above worked for me. Thanks