Home > Blockchain >  how to use xml slurper with jmeter jsr223 assertion
how to use xml slurper with jmeter jsr223 assertion

Time:01-20

I am trying to extract text from an element, using jsr223 assertion and XmlSlurper

offer=vars.get('CurrentOfferUnderTest')
def xml = new XmlSlurper(false,true).parseText(SampleResult.getResponseDataAsString())
if(offer=='410012'){
    //assert xml.ResultHeader.ResultCode.text()=='102020006'
    log.info(xml.Envelope.Body.LoanManageResultMsg.ResultHeader.ResultCode.text())
    log.info(xml.'*'.ResultCode.text())
    a=xml.'*'.find{node -> node.name()=='ns2:ResultCode'} //regardless of namespace, same result
    assert a.text()=='102020006'
}

whenever i do log just the xml var, i see text in the logs, when i try ad navigate as per above i get blanks\nulls. even when doing xml.Envelope.text() hence i added the namespace aware boolean. It didnt really help.What am i doing wrong?

XML excerpt:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <ns4:LoanManageResultMsg xmlns:ns4="http://www.p.com/wsdl/manageloanmgr"
                               xmlns:ns2="http://www.p.com/wsdl/shared"
                               xmlns:ns3="http://www.p.com/wsdl/loan"
                               xmlns:ns5="http://www.p.com/wsdl/newsubscriber"
                               xmlns:ns6="http://www.p.com/wsdl/query"
                               xmlns:ns7="http://www.p.com/wsdl/subscribe">
         <ResultHeader>
            <ns2:CommandId>LoanManage</ns2:CommandId>
            <ns2:Version>1</ns2:Version>
            <ns2:TransactionId>6</ns2:TransactionId>
            <ns2:SequenceId>4u6w6qry3</ns2:SequenceId>
            <ns2:ResultCode>102020006</ns2:ResultCode>
            <ns2:ResultDesc>Operation invalid.</ns2:ResultDesc>
            <ns2:OrderId>0</ns2:OrderId>

this did not help: enter image description here

More information:

  •  Tags:  
  • Related