Hi,
Quick question, I want to read the number alone which is middle of the text in web page.
For example…“Quote # 39281 created successfully”. How I can read only the 39281 number from the web page.
can you please suggest with the syntax i.e,
WebUI.getText(findTestObject(name of property)) !!
String txt = WebUI.getText(testObjectWithMessage)
Pattern pattern = Pattern.compile("[0-9]+")
Matcher matcher = pattern.matcher(txt)
String s = ""
if (matcher.find()) {
s = matcher.group()
} else {
KeywordUtil.markWarning("No number was found in a text.")
}
Please note, that current code takes the first number occurrence in the message, so if there are 2 or more numbers, only first one is stored.
Thanks for your reply, Marek.
I observed now that “testObjectWithMessage” is coming along with the number which number changes every time. So, I cannot store that in object repository. how do I store it ?
Thank you. Please find the below code.
The text displays along with the dispute number is “The dispute for system tracking # 1004100 has been submitted successfully”.
or as a method in a test case
def String numberFromString(String str) {
String numbers= str.replaceAll("[^0-9]", "")
}
println numberFromString("Quote # 39281 created successfully")
Log:
2019-06-25 16:05:26.554 ERROR c.k.k.c.c.keyword.CucumberReporter - it should displays create inquiry pages FAILED.
Reason:
groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.testobject.ObjectRepository.findTestObject()
is applicable for argument types: (org.openqa.selenium.By$ByXPath) values: [By.xpath: //td/table/tbody/tr/td]
Possible solutions: findTestObject(java.lang.String), findTestObject(java.lang.String, java.util.Map)
at CreateInquiry001.it_should_displays_create_inquiry_page2(CreateInquiry001.groovy:307)
at ✽.it should displays create inquiry pages(C:/Users/vdavuluri2/Katalon Studio/Govt Inquiry/Include/features/Create Inquiry-001.feature:55)
2019-06-25 16:05:26.560 WARN c.k.k.c.c.keyword.CucumberReporter - SKIP user capture the tracking number
2019-06-25 16:05:26.561 WARN c.k.k.c.c.keyword.CucumberReporter - SKIP user click on the close button at right side
2019-06-25 16:05:26.562 WARN c.k.k.c.c.keyword.CucumberReporter - SKIP user successfully logged off
HTML Page
I wanted to extract the text … “Create Inquiry Tracking # 596” & “The inquiry for system tracking # 596 has been submitted successfully” from the below