Using SOAP UI, automated tests can be created for web services and Test Web Service using SOAP UI.
In this article, we will
- Create a SOAP project using SOAP UI
- Create Assertions in SOAP UI
- Build an automated test using SOAP UI
First, you need to install SOAP UI from the URL https://www.soapui.org/downloads/soapui.html.
Create a SOAP project:
Step 1: Open SOAP UI.
Step 2: Press Ctrl + N to create a new project.
Step 3: Run the project and go to http://localhost:8080/ws-doc/.
Step 4: Enter the URL of WSDL in the field of Initial WSDL. The field Project Name will automatically get filled.
Step 5: Click on, OK. It will then create a new project.
Build a Test Suite, Test Case, and Test Step:
Step 1: Press Ctrl + T to create a new test suite.
Step 2: Click on, OK. Select the name of your Test Suite and press Ctrl + N to create a new Test Case.
Step 3: Click on, OK. Expand the Test Suite and Test Case. Right-click on the Test Step > Add Step > SOAP Request.
Step 4: Enter the name of the step and click on, OK.
Step 5: Select the option CustomerWebserviceSoap -> GetCustomers and click on OK.
Step 6: Again, click, OK.
Step 7: Open the SOAP request Retrieve Customers.
Step 8: Change the value from
<Offset>?</Offset>
<PageSize>?</PageSize>
To
<Offset>0</Offset>
<PageSize>10</PageSize>
Step 9: Press Alt + Enter to submit the request. The response will be:
<soap:Envelope xmlns:xsd="https://www.w3.org/2001/XMLSchema" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="https://www.example.com/"> <soap:Body> <tns:GetCustomersResponse> <Customer> <Name>Jessica D. Rogers</Name> <Address>2118 Collins Street</Address> <ZipCode>PA 16646</ZipCode> <City>Hastings</City> </Customer> <Customer> <Name>Jamie S. Wentz</Name> <Address>3269 Village View Drive</Address> <ZipCode>MD 20872</ZipCode> <City>Damascus</City> </Customer> <Customer> <Name>Blake G. Race</Name> <Address>4437 Sunny Glen Lane</Address> <ZipCode>OH 44115</ZipCode> <City>Cleveland</City> </Customer> <Customer> <Name>Angela L. Dolly</Name> <Address>3718 Alpha Avenue</Address> <ZipCode>TX 75439</ZipCode> <City>Ector</City> </Customer> </tns:GetCustomersResponse> </soap:Body> </soap:Envelope>
Create Assertions:
Step 1: Click Assertions (1).
Step 2: Click on the icon Add Assertion.
Step 3: Click Property Content > XPath Match. Enter the expression count(//Customer) and click on Save.
Extend your Test Case:
Step 1: Add a new Soap Request to the already available test cases.
Field | Value |
Specify name for step | Create Customer |
Select operation to invoke for request | CustomerWebServiceSoap -> CreateCustomer |
Step 2: Change the request.
<soapenv:Envelope xmlns:soapenv="https://schemas.xmlsoap.org/soap/envelope/" xmlns:exam="https://www.example.com/"> <soapenv:Header/> <soapenv:Body> <exam:CreateCustomer> <Name>Donald A. Hylton</Name> <Address>784 Better Street</Address> <City>Kansas City</City> <ZipCode>KS 66102</ZipCode> </exam:CreateCustomer> </soapenv:Body> </soapenv:Envelope>
Step 3: Add a Contains Assertion and enter true.
Step 4: Right-click on the test case, Retrieve Customers. Select the option Clone Test Step. Change the Test Step name to Retrieve Customers 2 and click on OK.
Step 5: Open Test Step Retrieve Customers 2. Click on Assertions (2). Open XPath Match – Unknown. Change the Expected Result to 1+ and click on button Save.
Run the Test Case:
Open Test Case TestCase 1.
Click on the icon Run this Test Case.