I have made a sample Test Case TC1
:
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import my.StringUtils
// String text = WebUI.getText(findTestObject('AddStateRoutingRule/Page_WellDyne QuickLook/p_Your new Routing Rule was successfully im_328405'))
String text = "Your new Routing Rule was successfully implemented. \u2010 Partner: FMC \u2212 Type: Direct \u2013 Lane: FL-RDS \u2014 State: MA . Click to View"
println("text: " + text)
String escp = StringUtils.escapeNonAsciiChars(text)
println("escp: " + escp)
String partner = 'FMC'
String type = 'Direct'
String lane = 'FL-RDS'
String state = 'MA'
String pattern = ".*Partner.*" + partner +
".*Type.*" + type +
".*Lane.*" + lane +
".*State.*" + state +
".*"
WebUI.verifyMatch(text, pattern, true, FailureHandling.CONTINUE_ON_FAILURE)
Also I have made a custom keyword my.StringUtils
:
package my
public class StringUtils {
/**
* convert the input string
* while escaping all non ASCII characters of which UNICODE code point is larger than 128
*
* E.g.,
* String s = "Hello\u2010world"
* println(s) // --> "Hello‐world"
* println(StringUtils.escapeNonAsciiChars(s)) // --> "Hello\u2010world"
*/
static String escapeNonAsciiChars(String str) {
StringBuilder sb = new StringBuilder()
for (int i = 0; i < str.length(); i++) {
int codepoint = str.codePointAt(i)
if (codepoint < 128) {
sb.append(str.charAt(i))
} else {
sb.append("\\u").append(String.format("%04X", codepoint))
}
}
return sb.toString()
}
}
(1) How to check the type of -
like character
When I ran the test case TC1
, it first prints a message in the console:
text: Your new Routing Rule was successfully implemented. ‐ Partner: FMC − Type: Direct – Lane: FL-RDS — State: MA . Click to View
escp: Your new Routing Rule was successfully implemented. \u2010 Partner: FMC \u2212 Type: Direct \u2013 Lane: FL-RDS \u2014 State: MA . Click to View
In the text
you find a few -
like characters. They look so similar that you can not differentiate them.
In the escp
you find those -
like characters are converted into UNICODE-escape fomart (\uxxxx). You can find U+2010 ‐ HYPHEN, U+2212 − MINUS SIGN, U+2013 – EN DASH, U+2014 — EM DASH.
@pasthana
I would recommend to you to apply my.StringUtils.escapeNonAsciiChars(String str)
method to your HTML text. You will find and be sure which of -
like character is used there.
(2) How to verify a text in HTML while disregarding ambiguous -
characters
As for text verification, I suppose that it is not significant for you which type of -
like character is used in the text. You rather want to disregard them, don’t you?
You can use Regular Expression here in order to implement such a-bit-sophisticated verification. In the TC1
I used WebUI.verifyMatch(String actual, String expected, Boolean isRegex, FailureHandling)
. WebUI.verifyElementText()
is not capable of performing matches with Regular Expression.
When I ran the TC1
, it passes.
When I change String state = 'foo'
and ran the TC1
, it fails (as I expected) with the following message.
2021-01-12 14:55:40.319 ERROR c.k.k.core.keyword.internal.KeywordMain - ❌
Unable to verify match between actual text
'Your new Routing Rule was successfully implemented. ‐ Partner: FMC − Type: Direct – Lane: FL-RDS — State: MA . Click to View'
and expected text
'.*Partner.*FMC.*Type.*Direct.*Lane.*FL-RDS.*State.*foo.*'
using regular expression (
Root cause: com.kms.katalon.core.exception.StepFailedException: Actual text 'Your new Routing Rule was successfully implemented. ‐ Partner: FMC − Type: Direct – Lane: FL-RDS — State: MA . Click to View' and expected text '.*Partner.*FMC.*Type.*Direct.*Lane.*FL-RDS.*State.*foo.*' are not matched using regular expression