I am very new to Groovy & Soap UI
I have response XML as
<carrierUDOResponse ReferenceId="" Result="SUCCESS" xmlns:xsi="" xsi:noNamespaceSchemaLocation="CarrierUDOReponse.xsd
<errors>
<error code="0" description="**i WANT TO ACCESS THIS**" property=""/>
</errors>
<warnings>
<warning code="0" description="" property=""/>
</warnings>
</errorsAndWarnings>
</carrierUDOResponse>
In the Groovy script I want to capture the value of attribute and pass it to next step. How should I capture?
The groovy script is below
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( "Create_shipment#Response" )
// loop item nodes in response message
for( item in holder.getNodeValues( "//error.code" ))
log.info "errors : [$item]"
def no = holder["count(//error)"]
@Rao provides the right answer
:)
, only to give and alternative instead ofXmlHolder
you can do the same with aXmlSlurper
as follows:Here is the groovy script that extracts the required description attributes using
xpath
.Looks like the given xml is partial, and not well formed.
In order to show you the how to extract the data, modified a bit of your xml snippet. But basically idea is same.
Here the variable
descriptions
contains the list of error descriptions.I am adding below information based on your statement that you wanted to use these descriptions in the following step. But, the information is not completely available how your use case is. Hoping that below would be helpful too.
If you want this data to be available to the next step, the following are possibilities. But it may vary how the data is really needed in the next step. Also note that here there are list of error descriptions available.
Use it in another groovy script: It is possible to pass data / object from one groovy script step to other groovy step using
context
variable. For example you can add the descriptions to context in the above groovy script, so that the same can be retrieved in the following step.Use it in another test request step (soap / rest): Here you will be able use a string data, but not really list can be used in a simple way.