How do I create a usable Web Test Object through scripting that will then link to an actual web page object in such a way that I can then gather information from its other property values.
I’ve attempted the addProperty option to give a created TestObject the correct “xpath”, but that doesn’t seem to link the TestObject to the actual web page object for later use.
I know that the web page objects that I want to look through have a parent object with a unique ID. EX: “//tr[@data-message-id=’###’]/td[2]”
Using MailCatcher:
The parent object is an individual email (in a table row – tr) and it has four children objects (each in a table data – td): from address, to address, subject, & date received
The parent object is also associated to an iframe that will display the body text of the email.
I would like to get the most recently received email and confirm that its 2nd, 3rd, & 4th children each have specific text, so that I know I have the correct email.
Unfortunately, I can’t just use the date received timestamp in the search box at the top, because the time that the test case initiates the email send is not the same as when that email is received.
Also, there may be other emails sent at similar times, which is why I would need to be able to look through multiple emails to find the correct one.
After I’ve found the correct email, I will then need to get some text (a url link) from the body of the email, which is in an iframe, and use that text to navigate to another page to complete the testing in full.
The URL link will change each time the test case is executed, but it will always be surrounded by the same text.
Brief layout of the steps I’m trying to accomplish:
I’m trying to figure out how to get Katalon to create a web object on the fly, based on looking through many similar objects from an xpath derivative to get confirmation information from a few of its children.
- Cycle through email objects based on numbered “data-message-id”s until desired email is found.
EX: “//tr[@data-message-id=’###’]/td[2]” - Get text from three of its children to confirm it’s the correct message.
EX: “//tr[@data-message-id=’###’]/td[2]”
EX: “//tr[@data-message-id=’###’]/td[3]”
EX: “//tr[@data-message-id=’###’]/td[4]” - Create a usable Test Object based on the ID.
- Click on that created Test Object on the web page to display body text in the iframe.
- Use a specific substring from the text in the associated iframe message body to continue the testing process.
Error being generated at this line from the CODE below: sToAddress = WebUI.getText(findTestObject('toEmailID'))
ERROR
=============== ROOT CAUSE =====================
Caused by: java.lang.IllegalArgumentException: Object is null
================================================
08-06-2020 01:56:41 PM sToAddress = getText(findTestObject("toEmailID"))
Elapsed time: 0.157s
Unable to get text of object (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to get text of object
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.GetTextKeyword.getText(GetTextKeyword.groovy:88)
at com.kms.katalon.core.webui.keyword.builtin.GetTextKeyword.execute(GetTextKeyword.groovy:67)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:72)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.getText(WebUiBuiltInKeywords.groovy:914)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$getText$5.call(Unknown Source)
at DeactivateUser.run(DeactivateUser:106)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1596740177555.run(TempTestCase1596740177555.groovy:25)
Caused by: java.lang.IllegalArgumentException: Object is null
at com.kms.katalon.core.helper.KeywordHelper.checkTestObjectParameter(KeywordHelper.java:33)
at com.kms.katalon.core.webui.keyword.builtin.GetTextKeyword$_getText_closure1.doCall(GetTextKeyword.groovy:76)
at com.kms.katalon.core.webui.keyword.builtin.GetTextKeyword$_getText_closure1.call(GetTextKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
at com.kms.katalon.core.webui.keyword.builtin.GetTextKeyword.getText(GetTextKeyword.groovy:88)
at com.kms.katalon.core.webui.keyword.builtin.GetTextKeyword.execute(GetTextKeyword.groovy:67)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:72)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.getText(WebUiBuiltInKeywords.groovy:914)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$getText$5.call(Unknown Source)
at Script1595625123189.run(Script1595625123189.groovy:106)
... 11 more
)
CODE
Boolean bEmailFound = false
String sToAddress
String sSubject
String sReceived
String sDesiredText = 'Something Important'
def date = new Date()
sdfDate = new SimpleDateFormat('ddddd, dd mmm yyyy')
sdfh = new SimpleDateFormat('h')
sdfm = new SimpleDateFormat('mm')
String sDate = sdfDate.format(date)
String sHour = sdfh.format(date)
String sMinute = sdfm.format(date)
int iHour = sHour.toInteger()
int iMinute = sMinute.toInteger()
TestObject tobEmail = new TestObject('toEmailID')
TestObject tobSubject = new TestObject('toSubjectID')
TestObject tobTimeStamp = new TestObject('toTimeStampID')
tobEmail.addProperty('xpath', ConditionType.EQUALS, "//tr[@data-message-id='20']/td[2]")
tobSubject.addProperty('xpath', ConditionType.EQUALS, "//tr[@data-message-id='20']/td[3]")
tobTimeStamp.addProperty('xpath', ConditionType.EQUALS, "//tr[@data-message-id='20']/td[4]")
for (int i = 20; i < 1000; i++) {
tobEmail = WebUI.modifyObjectProperty(tobEmail, 'xpath', 'equals', "//tr[@data-message-id='" + i + "']/td[2]", false)
tobSubject = WebUI.modifyObjectProperty(tobSubject, 'xpath', 'equals', "//tr[@data-message-id='" + i + "']/td[3]", false)
tobTimeStamp = WebUI.modifyObjectProperty(tobTimeStamp, 'xpath', 'equals', "//tr[@data-message-id='" + i + "']/td[4]", false)
sToAddress = WebUI.getText(findTestObject('toEmailID'))
sSubject = WebUI.getText(findTestObject('toSubjectID'))
sReceived = WebUI.getText(findTestObject('toTimeStampID'))
WebUI.comment("getText with findTestObject: $sToAddress $sSubject $sReceived")
if (sToAddress.contains('email@address.com')) {
if (sSubject.contains('Expected subject')) {
if (sReceived.contains("$sDate $iHour:$iMinute")) {
bEmailFound = true
}
iMinute++
if (sReceived.contains("$sDate $iHour:$iMinute")) {
bEmailFound = true
}
iHour++
iMinute = 0
if (sReceived.contains("$sDate $iHour:$iMinute")) {
bEmailFound = true
}
}
}
if (bEmailFound == true) {
WebUI.click(findTestObject('Page_MailCatcher/td_ToAddress'))
WebUI.waitForElementPresent(findTestObject('Page_MailCatcher/a_Plain text Tab'), 30)
WebUI.waitForElementClickable(findTestObject('Page_MailCatcher/a_Plain text Tab'), 30)
WebUI.click(findTestObject('Page_MailCatcher/a_Plain text Tab'))
WebUI.verifyTextPresent("Text To Extract URL From: $sDesiredText", true)
}
// Navigate to URL and finish test case
}