Your raw response contains the following <Return>
element.
<Return><?xml version="1.0" encoding="UTF-8"?> <DEX_Feedback><AsOf>2022-09-23T16:52:38</AsOf><DEX_File><Name_Submitted>20220923.165206.jpestest2.trans.002584.ext</Name_Submitted><Processing_Started>20220923/16:52:06</Processing_Started><Name_Inside_JOPES>20220923.165206.jpestest2.trans.002584.ext</Name_Inside_JOPES><messages></messages><result>DEX conversion completed: In /1/ Out /1/</result></DEX_File><Transactions><Transaction_Info><jsp_tsn>3333343848</jsp_tsn><processing_step><name>DEX_conversion</name><message>NONE</message><result>Successful conversion</result></processing_step><processing_step><name>Final_application</name><message></message><result>SUCCESS</result><trans_frag></trans_frag></processing_step></Transaction_Info></Transactions><Transaction_Summary><Total>1</Total><Pending>0</Pending><Success>1</Success><Success_with_warnings>0</Success_with_warnings><Rejected>0</Rejected></Transaction_Summary></DEX_Feedback></Return>
The <Return>
element here is a valid XML element which contains a text string which starts with <?xml
and ends with </DEX_Feedbback>
. This response is in a valid format as XML.
If you change your code as follows and ran it:
def response = findTestObject(âABC/GetTransactionsâ)))
String returnedStr =
WS.getElementPropertyValue(response,
"GetUploadFeedbackResponse.Return")
println "returnedStr: " + returnedStr
You will see in the console:
returnedStr: <?xml version="1.0" encoding="UTF-8"?> <DEX_Feedback><AsOf>2022-09-23T16:52:38</AsOf><DEX_File><Name_Submitted>20220923.165206.jpestest2.trans.002584.ext</Name_Submitted><Processing_Started>20220923/16:52:06</Processing_Started><Name_Inside_JOPES>20220923.165206.jpestest2.trans.002584.ext</Name_Inside_JOPES><messages></messages><result>DEX conversion completed: In /1/ Out /1/</result></DEX_File><Transactions><Transaction_Info><jsp_tsn>3333343848</jsp_tsn><processing_step><name>DEX_conversion</name><message>NONE</message><result>Successful conversion</result></processing_step><processing_step><name>Final_application</name><message></message><result>SUCCESS</result><trans_frag></trans_frag></processing_step></Transaction_Info></Transactions><Transaction_Summary><Total>1</Total><Pending>0</Pending><Success>1</Success><Success_with_warnings>0</Success_with_warnings><Rejected>0</Rejected></Transaction_Summary></DEX_Feedback>
Please note that <
is translated to <
and >
is translated to >
. Katalon Studio internally performs parsing the response XML, which results this implicit character translation. Your script does not have to do this character conversions for itself.
Please note also that your Groovy script regards the variable returnedStr
as of type java.lang.String
. Your script does NOT yet recognizes the returnedStr
variable as some object type for XML processing (e.g., org.w3c.dom.Document
).
A String
is just a string. The WS.getElementPropertyValue()
command can not look into a plain String. It can not recognize an XML element <Success>0</Success>
inside a string.
So, your Groovy script need to parse a plain String into an object of XML-type. Please read https://www.baeldung.com/groovy-xml to study how to process XML in Groovy.
The following code-snippet would do parsing a String to get an GPathResult and look into its element tree:
GPathResult xmlContent = new XmlSlurper.parse(returnedStr)
println "Success: " + xmlContent.Transaction_Summary.Success
// or may be
// println "Success: " + xmlContent.DEX_Feedback.Transaction_Summary.Success
// I am not sure
This will print
Success: 0