How to assign attributes of a node to variables to output to a log file?
Not sure how to assign the attributes of a node to variables so I can output to a log file. Please help.
The request contains 8 API and the result contains 9 responses (1 for the whole request and 8 individual responses of each API).
Below are the full response, the Groovy and the log.info.
Since I will have to process the teststep thousands of times with different data, the log file will be too big. I am hoping to assign MESSAGE1 to the status of API-1, MESSAGE2 to the status of API-2 and so on. This way, I can manipulate these MESSAGES to log.info as well as a external report file, preferably one line per teststep.
Something like:
Thu Jun 24 01:38:58 EDT 2021:INFO: Seq=0 302330000006120, 12313140097 FlowId: 1 Status: 0, FlowId: 2 Status: 0, FlowId: 3 Status: 0.....
Thu Jun 24 01:38:58 EDT 2021:INFO: Seq=0 302330000007120, 12313140098 FlowId: 1 Status: 0, FlowId: 2 Status: 0, FlowId: 3 Status: 0.....
Then the external report file:
Seq=0 302330000006120, 12313140097 FlowId: 1 Status: 0, FlowId: 2 Status: 0, FlowId: 3 Status: 0.....
Seq=0 302330000007120, 12313140098 FlowId: 1 Status: 0, FlowId: 2 Status: 0, FlowId: 3 Status: 0.....
----------------------------------------------------------------------------------------------------------------------------------------------
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:changeSdmDataResponse resultCode="0" message="success" xmlns:ns2="http://www.abcnumber.com/titan/sdm/soap/types">
<sdmDataResponse flowId="1">
<ns2:changeImsiDataResponse resultCode="0" message="success"/>
</sdmDataResponse>
<sdmDataResponse flowId="2">
<ns2:changeMsisdnDataResponse resultCode="0" message="success"/>
</sdmDataResponse>
<sdmDataResponse flowId="3">
<ns2:changeImsSubscriberDataResponse resultCode="0" message="success"/>
</sdmDataResponse>
<sdmDataResponse flowId="4">
<ns2:changeImsPrivateUserDataResponse resultCode="0" message="success"/>
</sdmDataResponse>
<sdmDataResponse flowId="5">
<ns2:changeImsPublicUserDataResponse resultCode="0" message="success"/>
</sdmDataResponse>
<sdmDataResponse flowId="6">
<ns2:changeImsPublicUserDataResponse resultCode="0" message="success"/>
</sdmDataResponse>
<sdmDataResponse flowId="7">
<ns2:changeImsPublicUserDataResponse resultCode="0" message="success"/>
</sdmDataResponse>
<sdmDataResponse flowId="8">
<ns2:changeImsSubscriberDataResponse resultCode="0" message="success"/>
</sdmDataResponse>
</ns2:changeSdmDataResponse>
</soap:Body>
---------------------------------------------------------------------------------------------------------------------------------------
...
def xmlResponse = tStep.getPropertyValue("Response")
def holder = groovyUtils.getXmlHolder(xmlResponse)
def xml = new XmlSlurper().parseText(xmlResponse)
log.info " Seq="+i+" "+data[0]+", "+data[1]
//Closure to show the details of the item as input data
def showDetails = { item ->
def sdms = xml.'**'.findAll {it.name() == item }*.parent()
sdms.each {
// log.info "${item} ==> FlowId: ${it.@flowId}, ResultCode: ${it."$item".@resultCode}, Message: ${it."$item".@message}"
log.info "${item} ==> FlowId: ${it.@flowId}, Status: ${it."$item".@resultCode}"
}
}
showDetails('changeImsiDataResponse')
showDetails('changeMsisdnDataResponse')
showDetails('changeImsSubscriberDataResponse')
showDetails('changeImsPrivateUserDataResponse')
showDetails('changeImsPublicUserDataResponse')
...
...
-------------------------------------------------------------------------------------------------------------------------------------
Log.Info
Thu Jun 24 01:38:58 EDT 2021:INFO: Seq=0 302330000006120, 12313140097
Thu Jun 24 01:38:58 EDT 2021:INFO:changeImsiDataResponse ==> FlowId: 1, Status: 0
Thu Jun 24 01:38:58 EDT 2021:INFO:changeMsisdnDataResponse ==> FlowId: 2, Status: 0
Thu Jun 24 01:38:58 EDT 2021:INFO:changeImsSubscriberDataResponse ==> FlowId: 3, Status: 0
Thu Jun 24 01:38:58 EDT 2021:INFO:changeImsSubscriberDataResponse ==> FlowId: 8, Status: 0
Thu Jun 24 01:38:58 EDT 2021:INFO:changeImsPrivateUserDataResponse ==> FlowId: 4, Status: 0
Thu Jun 24 01:38:58 EDT 2021:INFO:changeImsPublicUserDataResponse ==> FlowId: 5, Status: 0
Thu Jun 24 01:38:58 EDT 2021:INFO:changeImsPublicUserDataResponse ==> FlowId: 6, Status: 0
Thu Jun 24 01:38:58 EDT 2021:INFO:changeImsPublicUserDataResponse ==> FlowId: 7, Status: 0
Here you go:
If that is output you need? Then please use
//Assuming you have data array, variable i, and xmlString //Apart from that you can remove everything from the script def line = ["Seq=${i}", data[0], data[1] ] line << new XmlSlurper().parseText(xmlString).'**'.findAll {it.name() == 'sdmDataResponse' }.collectMany{ ["FlowId=${it.@flowId}", "Status=${it.children()[0].@resultCode}" ]} log.info line.flatten()
- I thought I saw those brackets from your response.
Just change
line.flatten()
To
line.flatten().join(',')