Verify Text Exists in Element

Disclosure: New Katalon User mostly using Record function and Manual

Our site is a database that can be searched and the results refresh within an element when the user submits the query.

What we are trying to do is verify that certain text exists in the results table. The Verify Text option searches the whole page so that’s a no go since the search term exists on the page. The Verify Element Text option appears to want to match the entire text string of the element instead of just finding the word within the element.

I see there is an option for GetText and that seems to be the right path, but I don’t know how to then check that text for a single word.

Any help would be appreciated.

1 Like

You would benefit greatly from learning how to use Script view (instead of or as well as Manual view), because…

in Script, you can do something like this:

String text = WebUI.getText(findTestObject("path/to/my/test object"))
if(text.contains("Jason")) {
  println("Eureka! I found Jason! :) ")
} else {
  println("Sorry, Jason is not around :( ")
}
1 Like

Thanks, Russ. This may be a silly follow-up question, but maybe I am just missing something elementary. The println function: can you base a pass/fail on this? Like if text.contains(“Jason”)) test case passes?

Also, any solid resources for learning to use script view? It seems fairly intuitive when looking at it, but always happy to learn more.

Thanks again.

1 Like

No. They’re typically seen in situations like that example I gave to signify “your code here” but actually doing something meaningful (e.g. the output will appear in the console in KS).

To fail a test at that point, use the KeywordUtil class markFailed or markFailedAndStop methods.

https://docs.katalon.com/javadoc/com/kms/katalon/core/util/KeywordUtil.html

You need three things:

  1. Guts
  2. Curiosity
  3. The address of this forum

Seriously, “the water’s fine” as they say. Jump in. If you get stuck, ask here. There’s a bunch of us regulars (spread all over the globe) just itching to help :wink:

As a first step - write some tests the usual way. Check the Script view. Make changes in Manual View. Check how they appear in Script View. Repeat.

You still here? Go!

3 Likes

@jroman the print will just throw a message on the console.
you can start to understand the script view voodoo by reading this, is a nice lecture:

https://www.tutorialspoint.com/groovy/index.htm

hint: skip the installation part. just go to the part where the programming stuff starts. do not be ashamed if you don’t understand everything from the begining and don’t attempt to read it in a single day.
take your time, small steps, explore, redo … learning is a continuous process

3 Likes

I’m still here and appreciate the help. I’m sure you’ll be hearing from me plenty!

2 Likes

Just a quick update…I was able to accomplish this using a combination of GetText, If-Else and KeywordUtil.markFailed

  result = WebUI.getText(findTestObject("path/to/my/test object")

    if (result.contains('ipad')) {
        println('Look, I found it!')
    } else {
        KeywordUtil.markFailed
    }

Hopefully, this does the trick…all tests have worked accurately so far. Thanks for the help.

1 Like