Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing XML response in SoapUI Pro using Groovy
    primarykey
    data
    text
    <p>I am using a groovy script to validate the response to my SoapUI xml requests.</p> <p>I have a datasheet that holds my test inputs as well as the xpath of the element I am wanting to validate in the xml response and the expected result.</p> <p>xml element = //ns1:warningCode[1] expected value = W0026</p> <p>My problem is, sometimes my xml responses will return other warning codes in addition to the one that I am wanting to validate</p> <p>e.g. I might get the below as part of my xml response..</p> <p>. . . </p> <pre><code>&lt;NS1:departmentReference&gt;200001060&lt;/NS1:departmentReference&gt; &lt;NS1:customerReference&gt;invalid dept ref&lt;/NS1:customerReference&gt; &lt;NS1:senderReference&gt;sendRef&lt;/NS1:senderReference&gt; &lt;/NS1:requestedShipment&gt; &lt;/NS1:completedShipmentInfo&gt; &lt;NS1:integrationFooter&gt; &lt;warnings xmlns="http://www.rmg.com/integration/core/V1"&gt; &lt;warning&gt; &lt;warningCode&gt;W0022&lt;/warningCode&gt; &lt;warningDescription&gt;The customerReference specified is longer than 12 characters and has been truncated&lt;/warningDescription&gt; &lt;/warning&gt; &lt;warning&gt; &lt;warningCode&gt;W0026&lt;/warningCode&gt; &lt;warningDescription&gt;The departmentReference specified is invalid and will be ignored&lt;/warningDescription&gt; &lt;/warning&gt; &lt;/warnings&gt; </code></pre> <p>. . .</p> <p>For my particular test I might only be wanting to check that the second warning is displayed. This means that I need to a) either ensure my test data will not produce any other warning messages or b) know how many warning messages will be returned and what order they will be displayed in so that my xpath is correct.</p> <p>I would like to know how to rewrite my script so that it will pass if there is any warningCode element that contains the code I am expecting irrespective if it is the first and only or 3rd warningCode element.</p> <p>Here is my full groovy script for the validation ...</p> <pre><code>import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; def dataSource = testRunner.testCase.getTestStepByName( "DataSourceShipmnt_v04" ); def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context); def response = context.expand( '${createShipmnt_v04#Response}' ); def holder = groovyUtils.getXmlHolder(response); //testElementOne will be something like '//ns1:warningCode[1]' or '//ns1:status/code' def testElementOne = context.expand( '${DataSourceShipmnt_v04#testElement1}' ); def testElementTwo = context.expand( '${DataSourceShipmnt_v04#testElement2}' ); //expectedResp1 will be a warning code e.g W0026 def expectedResp1 = context.expand('${DataSourceShipmnt_v04#expectedResp1}'); def expectedResp2 = context.expand( '${DataSourceShipmnt_v04#expectedResp2}' ); def actRtrn1; def actRtrn2; def result; //just a string value to return pass or fail. try { actRtrn1 = holder.getNodeValue(testElementOne); actRtrn2 = holder.getNodeValue(testElementTwo); }catch(Exception ex){} if ( actRtrn1 == expectdResp1 &amp;&amp; (actRtrn2 == expectdResp2 || actRtrn2 == null) ) { result = "pass"; } else { result = "fail"; } </code></pre> <p>Any help would be greatly appreciated.</p> <p>Thanks. Tam.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload