2011年11月21日 星期一

soapUI - Validate XML Messages

How do we use soapUI to validate XML messages? It's easy. The following example comes from this post.

To validate XML messages, right click EchoService > New TestSuite > Specify name of TestSuite: CheckItOut to create a new test suite:

Right click the white color area > New TestCase > Specify name of TestCase: CheckItOutOnce to create a new test case. (Or by clicking the most left-top button.)
Click the most left-top SOAP button > Create a new Test Request TestStep > Specify name for new step: CheckItOut > Select operation to invoke for request: EchoServiceEndpointPortBinding -> echo > OK (Or by right click the upper white area...)

Now we prepare our SOAP request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:demo="http://demo/">
   <soapenv:Header/>
   <soapenv:Body>
      <demo:echo>
         <word>check it out!</word>
      </demo:echo>
   </soapenv:Body>
</soapenv:Envelope>

The expected response should be
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:echoResponse xmlns:ns2="http://demo/">
         <return>check it out!</return>
      </ns2:echoResponse>
   </S:Body>
</S:Envelope>

To validate it, click Assertions (1) button > click the most top-left button > Select Assertion: XPath Match > click the left button. We will use the XPath match to validate XML Messages.

We want to validate if the SOAP response returns "check it out!." Therefore, in the XPath Match Configuration window, the expected result should be "check it out!" simply. To select the result, XPath expression should be
declare namespace ns2="http://demo/"
//ns2:echoResponse/return
where L1: namespace declaring and L2: XPath query. Save!

After saving, the new assertion should be valid:
Good! We can validate whether the echo method is correct or not.

Reference:

沒有留言:

張貼留言