software testing company
UI/UX

How to get started with SoapUI assertions? | Software Testing Company

A standard protocol SOAP (Simple Object Access Protocol) is used for sending and receiving web service requests and response. In SOAP, the data is platform independent, uses XML format to send and receive the request. A SOAP envelope is used for message exchange between sender and receiver application. To escape from messages getting blocked by the firewall, it uses simple SMTP and HTTP transport protocol.

SoapUI

SoapUI is a solution for functional testing in open-source cross platforms. It allows anyone to easily create and execute automated functional, regression, load and compliance tests. SoapUI is very simple, with no limits, and provides full test coverage. It has built-in reporting capabilities, and also automated testing solutions includes data-driven tests, load, and scenario-based tests.

Data Driven test

The simplest form , where the tester supplies the inputs from the row in the table and expects the outputs which occur in the same row.

Load testing

Is performed to determine a system’s behavior under both normal and anticipated peak load conditions.

Scenario-Based testing

Scenario testing is done to make sure that the end to end functioning of software is working fine, or all the business process flows of the software are working fine.

Test structure of SoapUI:

Test Suite, Test Case, Test Step are structured in a functional test of SoapUI.

Create a Project
  1. Create a project by clicking on File -> New SOAP Project
  2. New SOAP Project window gets open, Enter the project name and WSDL, and click OK.
  3. Upon creating the SOAP project with the above-said WSDL, we will be able to see that there are two operations that will be imported into the project.

Expand the first request and double click on the ‘Request1?. It will display the SOAP request in the XML format. For invoking an operation can add any number of request objects to an operation in the navigator tree, SoapUI by default creates a sample request for each operation when importing.

The editor window having 2 panels to view Request(left) and Response(Right) as shown above.

The XML on right side of the operation request 1, give FromCurrency and ToCurrency(in the“?” area), to know the expected result click on submit on the top left of request 1 XML format
When the request is submitted , it is processed by the web server and can be concluded as 1 unit of SAR= 16.9319 units of INR

At this point, we will be a little confused, when one can test directly the Web Service then what is the use for Test Cases. Well,we can send a request for one operation, what about others? we have to keep on editing each request, For example, If we want to convert from USD to INR instead of SAR to INR You need to edit the operation again. So, one has to create a test suite/cases to have all possible scenarios need to test without having to directly edit the operation itself.

Create a Test Suite

A test suite is a collection of test cases intended to test a behavior or a set of behaviors of the software program.

Within the project, we can create a test suite by performing a right click on the root of the projects.

We need to enter the name of the test suite and press OK.

Within a test suite, we can create multiple tests by performing a right click on the ‘test suite’ and choosing ‘New Test Case’.

Specify the name of the test case and click ‘OK’.

Note: We can see that the test case is added with zero test steps for all kinds of tests available. Upon adding the test steps the numbers in the bracket would change automatically. The functional should go into “Test Steps”while performance test step should go into “Load Test” and a security test step should go into “Security Tests”.

Test Step Insert

We can insert a variety of test steps by performing a right click on test steps and selecting an appropriate test step as shown below.

• Let’s start with Test request, when clicked on test request a pop window appears to enter the step name, by clicking on “OK” another window appears which we have to select the operation to invoke. All the operations are listed, and the user can select the operation that they would like to invoke.

• There are two operations that will be listed. Both the Operations are the same except the SOAP version used.
• CurrencyConvertorSoap – uses SOAP version 1.1 whereas,
• CurrencyConvertorSoap12 – uses SOAP version 1.2
• The Version does not matter for us in this context. Hence you can select one of your choices.

A window gets open after clicking on “OK”, to the current window we can add assertions (checkpoints/validation) points.

Note- What does assertion mean?—-Assertion means the act of affirming or stating something. It can also be interpreted as checkpoint or a validation point.Once a request is sent to a web server a response is received. We need to validate if the response contains the data that we expect. In order to validate the response, we need to use assertions.

Upon creating the test case, the request XML gets created.

The test step count is now incremented to one as we have just added one test step. Similarly, upon adding load and security tests step, the corresponding number would be automatically incremented based on the number of steps added.

Executing Test Step

To execute the newly added test case, select the test case , give the currencies to be converted, then follow the same procedure once it is executed, the left side of the “SAR to INR”turns to green.

Likewise, the steps get added up, so no steps will be missed.

Assertions

In order to validate the response, we need to use assertions.

Types Of Assertion

There are various ways of asserting a response; however, we will focus on the commonly used Assertions types while validating a response.

  1. Contains Assertion
  2. Not contains Assertion
  3. X Path Match Assertion
  4. X Query Match Assertion
  5. Scripting Assertion

Note- Before giving values for “FromCurrency” and “ToCurrency” assertion should be added, then only execution button should be pressed.

Contains Assertion

Searches for the existence of the specified string. It also supports regular expression.

Step 1: By Default there are no assertions.

• The Number of Assertions are shown in the Assertions Tab.
• To add a new assertion, click on ‘Add New Assertion’ button.

Step 2: Now,

  1. Select the Assertion Category.
  2. Select the Assertion Type.
  3. Click ‘Add’

After adding Contains Assertions, execute the operation, if the result matches with the contain assertion’s value given, it shows- Contains Valid.

Not Contains Assertion

Searches for the Non-existence of the specified string. It also supports regular expression.

Step 1: Now after clicking on ‘add new assertions’ button,

  1. Select the Assertion Category.
  2. Select the Assertion Type – In this case ‘NOT Contains’
  3. Click ‘Add’

Step 2: Let us validate if the string ‘ToCurrency’ exist in the response. Enter the string ‘TOCurrency’ and Click ‘OK’

XPath Match Assertion

Uses XPath expression to select the target node and its values. XPath is an XML query language for selecting nodes from an XML document.

Step 1: Now after clicking on ‘Add New Assertions’ button,

  1. Select the Assertion Category.
  2. Select the Assertion Type – In this case ‘XPath Match’
  3. Click ‘Add’

Step 2: Add XPath Window

  1. Before Adding XPath, we need to declare the NameSpace. An XML namespace is a collection of names, identified by a Uniform Resource Identifier (URI) reference, which is used in XML documents as element and attribute names. The same is used in SOAPUI XPath Assertion.
  2. For declaring XML Namespace, we just need to click on ‘Declare’ button which would do the job for us else we can also manually declare a namespace ourselves.
  3. After declaring the namespace we need to refer the XPath using the created namespace.
  4. Upon clicking the ‘Declare’ button, two namespaces will pop up as we have two URI’s. One of them is the schema URL and the other one corresponds to the actual web service URL. We need to use the actual namespace where the web service is located and NOT the schema namespace while referencing XPath.
XQuery Match

Uses an XQuery expression to select content from the target property.

Need help?  Perfomatix |Software Testing

We are Perfomatix, a top Software Testing company. We specialize in building highly scalable APIs and Mobile apps and we also have strong expertise in IoT appsVirtual Reality apps, and Augmented Reality appsGet in touch with us to find out how we can help in shaping your disruptive idea into a prototype, MVP and finally into a killer product. Visit our success stories section to find out more about some of the startups which made it big with us.

Perfomatix | Product Engineering Services Company