Partial Text Validation in Katalon

Need some help in below 2 things:

  1. I don’t see a keyword for Partial Text in Katalon. Can someone please advise how to use validate part of a text?
    I have a dynamic data coming after a text. I only want to validate against static data.
    Eg: Payment Received for $600.Receipt Date:3/5/2025.

I only want to check if the text-"Payment Received for $600 is visible in the UI or not.

  1. Need help in splitting date and time from a string.

Eg: I have captured a text from a field “Your Date Time is 3/5/2025, 3:22 pm.”
I need to get the date part only from the string which is 3/5/2025.
Please advise.

1 Like

You can find partial text in several manners, but I use the String method, “contains()”, like:

WebUI.verifyMatch(WebUI.getAttribute(findTestObject('...'), "value").contains("your partial text").toString(), "true", false)

or
WebUI.verifyMatch(WebUI.getText(myItem).contains('780').toString(), "true", false)

Note: “contains()” returns a boolean value (true or false). If you want, you can just verify with an “Assert” statement.

Another method is to use Regular Expression (RegEx) in which you match with wildcard, like:

WebUI.verifyMatch(WebUI.getText(findTestObject('myPage/li_LastUpdatedTimeStamp')),
   "(?i)Last Updated by ${gUserName} on ${gFormattedDate} .*", true)

WebUI.verifyMatch(WebUI.getText(findTestObject('...')),
		gFormattedDate + "\\s\\d{1,2}:\\d{2}\\s(a|p)m.", true)

To use RegEx with “verifyMatch”, change the last boolean value to “true”. You should read up on RegEx because there are several characters that act differently than regularly, such as {, \, ( and )

In the first example I start with “ignore letter case” and at the end I have the wildcard, (Katalon has it as a period with asterisk), to match everything else after the date. In the second example, I try to match a specific phrase based on characters: a space, either one or two digits, a colon, then two digits followed by another space and then either an “am” or “pm” ending in a period, similar to your “3/5/2025, 3:22 pm.”

For this, I might use either the “split()” function or “substring()” function, like:

def msg = "Your Date Time is 3/5/2025, 3:22 pm."
def dateTime = msg.split('is ')[1]
WebUI.comment("We now have ${dateTime}")

subDateTime = msg.substring(18)
WebUI.comment("We now have ${subDateTime}")

Thanks for the help @grylion54
I tried the approach but I am getting an error using substring.
Also, I needed only Date part 3/5/2025 and not Date and Time(3/5/2025, 3:22 pm)


I gave you a link to the format of “substring” so that you could help yourself if you needed to amend your information in any variety of ways, for future reference. Same for “split”.

So, “substring” can have a second parameter that would be the ending position, like:
substring(start position, end position)
Note: start position “starts” counting from 0 (zero). So the first position letter ‘Y’ is 0.

def msg = "Your Date Time is 3/5/2025, 3:22 pm."
def subDate = msg.substring(18, 26)
WebUI.comment("We now have ${subDate}")

should produce: 3/5/2025

subDate = msg.substring(5, 10)
WebUI.comment("We now have ${subDate}")

should produce: Date

Obviously, you CANNOT use numbers that are LARGER than the length of String that you have!

I tried this on
String msg=“3/5/2025, 3:22 pm”
String date = msg.split(‘,’)[0]

Got O/P: 3/5/2025

2 Likes