As I mentioned in my previous post, soapUI can build a basic test suite from a WSDL. For this mini-tutorial, I'll be using a web service based on the periodic table of elements that allows users to retrieve symbols, atomic weights, etc. In soapUI, select File - New soapUI Project and enter a Project Name and the following Initial WSDL/WADL:
http://www.webservicex.net/periodictable.asmx?WSDL
Check the box to generate a test suite and click OK. You'll see soapUI automatically load definitions for our web service, after which it prompts the user for test suite creation options, which include selecting which operations you'd like to include and how you'd like them grouped in test cases. Just accept the defaults here (you may be prompted twice-- soapUI is building test suites for SOAP 1.1 and 1.2 bindings; you can use either for the following examples).
On the left-hand side of the window you'll see the workspace navigator; after a successful import you'll see interfaces and generated test suites for the web service.
soapUI Workspace Navigator
Using the default options, each operation will have its own test case consisting of a single SOAP request test step. Let's actually build a test request and send it to the web service. Drill down into the test suite for the periodic table web service and double-click on the GetElementSymbol test step to launch the test step editor. The GetElementSymbol operation takes a single input parameter, an element name, and returns its symbol in the periodic table. Modify the test request in the left pane of the editor so the ElementName parameter is "Silver" (replace the "?" between the ElementName tags with "Silver"). Then click the Submit Request button at the top of the window-- the leftmost button that looks like a Play button. The test request is sent to the web service and you should see the response in the right pane.
SOAP Request Test Step
Now that we have a working SOAP request test step we'll want to create some assertions to validate our response data. Click the Assertions button at the bottom of the soapUI window to expand the Assertions panel (displayed across the lower part of the window). Click the Add Assertions button (leftmost button at the top of the Assertions panel) to launch the Add Assertion dialog-- here you can look through some of the different Assertion types that are available.
From the SLA section, select the Response SLA assertion type and click Add. This assertion type confirms that the given test request receives a response within a specified period of time; you'll be prompted to specify the acceptable response time (in milliseconds) before the assertion is added. Enter 10000 (10 seconds) here.
Add a Not SOAP Fault assertion (from the Compliance, Status and Standards section) to verify that the test response is not a SOAP Fault, and finally, add a Contains assertion from the Property Content section to validate response data. Since this particular SOAP request is pretty straightforward with only one piece of data returned in the response (the element's symbol), the Contains assertion should be adequate. You'll be prompted to enter a string to look for in your test response; enter text matching the response's Symbol element: "
For any subsequent runs of your test step, your SOAP response will be validated automatically against the added assertions with the pass/fail status of each indicated by "green light"/"red light" icons in the Assertions panel.
The SOAP Request test step is just one test step type-- in the next post, we'll look at some of the others.
Nice post to learn assertions. I like it very much as it is in very detailed way for begineers.i look forward to see some more tutorials.
ReplyDeleteI get this error when running
ReplyDeleteSystem.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.IO.IOException: There is not enough space on the disk.
There's been an ongoing issue with webservicex.net that results in that error. You can try alternative web service WSDLs. Two sites I've used to find free web services are xmethods.net and programmableweb.com. One service that seems to be working now is http://www.holidaywebservice.com/Holidays/HolidayService.asmx?WSDL ...
Delete