Test Web Services Using SoapUI

Last modified: August 20, 2024

Introduction

You can publish your own web services in a Mendix application. These webservices consist of operations. Other applications can then call operations of this webservice and you can return a result. This result is based on a microflow that will be executed when the web service is called. With SoapUI you can create (automated) tests for these webservices.

This how-to teaches you how to do the following:

  • Create a SOAP project with SoapUI
  • Create assertions in SoapUI
  • Build an automated test using SoapUI

Preparation

Before you start this how-to, make sure you have completed the following prerequisites.

Software Version used in this how-to
SoapUI 5.7.0

Publishing More Microflows as Web Service Operation

In Expose a Web Service you already published the microflow GetCustomers as web service operation. In this chapter you will create two more microflow and publish them as web service operation.

  1. Open Studio Pro.

  2. Open the app you created in How to Expose a Web Service.

  3. Create a Microflow that creates a customer and returns a Boolean:

  4. Create a Microflow that deletes a customer and returns a Boolean:

  5. Publish both microflows as web service operation of the CustomerWebservice as described in chapter 4 of How to Expose a Web Service.

Creating a New SOAP Project

In this chapter you will create a new SOAP project.

  1. Open SoapUI.
  2. Press Ctrl + N to create a new SOAP project.
  3. Run your app locally in Studio Pro.
  4. Go to http://localhost:8080/ws-doc/.
  5. Enter the URL of the WSDL schema in the Initial WSDL field in SoapUI. The Project Name field will automatically be filled with the name of the webservice following by ?wsdl.
  6. ClickOK. This will create a new SOAP project in SoapUI.

Building a TestSuite, TestCase, and TestStep

In this chapter you will build a testsuite. A testsuite contains one or more testcases. Every testcase contains one ore more teststeps.

  1. In SoapUI, press Ctrl + T to create a new TestSuite.

  2. Click OK.

  3. Select TestSuite 1 and press Ctrl + N to create a new TestCase.

  4. Click OK.

  5. Expand TestSuite 1 and TestCase 1.

  6. Right-click Test Steps(0) and select SOAP Request.

  7. Enter Retrieve Customers in the name field.

  8. Click OK.

  9. Select CustomerWebserviceSoap -> GetCustomers.

  10. Click OK.

  11. Click OK.

  12. Open SOAP request Retrieve Customers.

  13. Change the follow value:

    <Offset>?</Offset>
    <PageSize>?</PageSize>
    

    into

    <Offset>0</Offset>
    <PageSize>10</PageSize>
    
  14. Press Alt + Enter to submit the request. The customers you created in the previous how-to will be shown in the response. The response will look like the code below:

    <soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://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>
    

Assertions

Assertions are used to validate the message received by a TestStep during execution, usually by comparing parts of the message (or the entire message) to some expected value. In this chapter you will create an assertion that validates the number of customers.

  1. Click Assertions (1).
    In chapter 3 step 9 the Add SOAP Response Assertion checkbox was checked. That is the first assertion you see in the list, SOAP Response - VALID.
  2. Click the add assertion icon.
  3. Click Property Content.
  4. Click XPath Match.
  5. Enter count(//Customer) in the XPath Expression field.
  6. In step 1.4 of the previous how-to you have added some data. Enter the number of created customers in the Expected Result field. In this example four customers were created.
  7. Click Save.

Extending Your Test Case

In this chapter you will extend your test case with multiple test steps and assertions.

  1. Add a new SOAP request to the existing test case with the following details:

    Field Value
    Specify name for step Create Customer
    Select operation to invoke for request CustomerWebServiceSoap -> CreateCustomer
  2. Change the request into the following value:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:exam="http://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>
    
  3. Add a Contains Assertion and enter true in the content field.

  4. Right-click test step Retrieve Customers.

  5. Select Clone TestStep.

  6. Change TestStep Name to Retrieve Customers 2.

  7. Click OK.

  8. Open teststep Retrieve Customers 2.

  9. Click Assertions (2).

  10. Open XPath Match - Unknown.

  11. Change Expected result to 1 + [the number you entered in step 5.6].

  12. Click Save.

  13. Add a new SOAP request to the existing test case with the following details:

    • In the Specify name for step, enter Delete Customer.
    • In the Select operation to invoke for request field, enter CustomerWebServiceSoap -> DeleteCustomer.
  14. Change the request into the following value:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:exam="http://www.example.com/">
       <soapenv:Header/>
       <soapenv:Body>
          <exam:DeleteCustomer>
             <Name>Donald A. Hylton</Name>
          </exam:DeleteCustomer>
       </soapenv:Body>
    </soapenv:Envelope>
    

Running the Test Case

In this chapter you will learn how to run the testcase you created in previous chapters.

  1. Open testcase TestCase 1.
  2. Click the run this testcase icon.

Congratulations! You have just created your first automated test with SoapUI.

Read More

Learn more about this topic using the following helpful links: