Step-by-Step Guide to Test SOAP Services with JMeter

Last Updated On

HOME


SOAP is a messaging protocol specification for exchanging structured information in the implementation of web services. Its purpose is to induce extensibility, neutrality, and independence. Testing SOAP (Simple Object Access Protocol) services using JMeter requires setting up a test plan. The test plan simulates requests. It also analyzes responses from the SOAP web service.

Here’s a detailed guide to help you test SOAP services using JMeter:

The sample request and response used in this tutorial are shown below:

Sample Request

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <NumberToWords xmlns="http://www.dataaccess.com/webservicesserver/">
      <ubiNum>500</ubiNum>
    </NumberToWords>
  </soap:Body>
</soap:Envelope>

Sample Response

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <m:NumberToWordsResponse xmlns:m="http://www.dataaccess.com/webservicesserver/">
      <m:NumberToWordsResult>five hundred </m:NumberToWordsResult>
    </m:NumberToWordsResponse>
  </soap:Body>
</soap:Envelope>

1. Create a Test Plan in JMeter


2. Add Thread Group

  • Select Test Plan on the tree
  • Add Thread Group                                                                                                                               
  • To add Thread Group: Right-click on the “Test Plan” and add a new thread group: Add -> Threads (Users) -> Thread Group

In the Thread Group control panel, enter Thread Properties as follows:

3.  Adding JMeter elements  

The JMeter element used here is HTTP Request Sampler. In the HTTP Request Control Panel, the Path field indicates which URL request you want to send

Add HTTP Request

The below-mentioned are the values used in HTTP Request to perform the test

  • Protocolhttps
  • Server Name or IPhttp://www.dataaccess.com
  • Method POST
  • Path – /webservicesserver/NumberConversion.wso

Add HTTP Head Manager

SOAP requests require specific content-type headers. The Header Manager lets you add or override HTTP request headers like can add Accept-Encoding, Accept, Cache-Control

To add: Right-click on Thread Group and select: Add -> Config Element -> HTTP Read Manager

The below-mentioned are the values used in Http Request to perform the test
Content-type = text/xml

5. Adding Listeners to Test Plan

Listeners – They show the results of the test execution. They can show results in a different format such as a tree, table, graph, or log file

We are adding the View Result Tree listener & Aggregate Report listener.

View Result Tree

View Result Tree shows the results of the user request in basic HTML format
To add: Right-click on Test Plan, Add -> Listener -> View Result Tree

Aggregate Report

It is almost the same as Summary Report except Aggregate Report gives a few more parameters like, “Median”, “90% Line”, “95% Line” and “99% Line”.

 To add: Right Click on Thread Group > Add > Listener > Aggregate Report

6. Save the Test Plan

To Save: Click File and Select -> Save Test Plan as ->Give the name of the Test Plan. It will be saved in .jmx format.

7. Run the Test Plan

Click on the Green Triangle as shown at the top to run the test.

8. View the Execution Status

Click on View Result Tree to see the status of Run. A successful request will be of a Green colour in the Text Section.

Click on Response data and Response Header to view other information about Response.

Click on Aggregate Report Result to see the aggregated status of Run.

We are done! Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!!

Additional Tutorials

How to send GET Requests in JMeter
JMeter Authorization with access token
How to generate JMeter HTML Report? 
Constant Throughput Timer in JMeter
How to generate Random Variables in JMeter

How to test SOAP Services using Rest Assured

HOME

In this tutorial, I will test a SOAP Service using Rest Assured. I will verify the status code, line of Status, and content of the Response. To set up a basic Rest Assured Maven Project, click here and Gradle project, click here.

Add the below-mentioned dependencies to the pom.xml.

<dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.13.1</version>
      <scope>test</scope>
</dependency>
 
<dependency>
      <groupId>io.rest-assured</groupId>
      <artifactId>rest-assured</artifactId>
      <version>5.3.2</version>
      <scope>test</scope>
</dependency>

What is the SOAP WebService?

SOAP is an XML-based protocol for accessing web services over HTTP. It has some specifications that could be used across all applications.

Implementation Steps:

Step 2 – Specify the base URL to the RESTful web service using the RestAssured class.

RestAssured.baseURI = "http://www.dneonline.com";

Step 3  The response to a request made by REST Assured.

  Response response = given()

Response is imported from package:

import io.restassured.response.Response;

Step 4 – Set the content type to specify the format in which the request payload will be sent to the server. Here, the Content-Type is “text/xml; charset=utf-8”.

 .header("Content-Type", "text/xml; charset=utf-8")

Step 5 Pass Request Body.

   .body(requestBody)
 requestBody = new File(getClass().getClassLoader().getResource("Number.xml").getFile());

Step 6 – Send the POST request to the server and receive the response of the request made by REST Assured. This response contains every detail returned by hitting request i.e. response body, response headers, status code, status lines, cookies, etc. The response is imported from package:

import io.restassured.response.Response;

Step 7 – To validate a response like status code or value, we have used the below code

 Assert.assertEquals(200, response.statusCode());
Assert.assertEquals(13, result);

PrettyPrint() – It prints the response body if possible and returns it as a string. Pretty printing is possible for content types JSON, XML, and HTML.

System.out.println(response.prettyPrint());

Below is an example of testing a SOAP Web Service request using the Rest Assured.

import io.restassured.response.Response;
import org.junit.Assert;
import org.junit.Test;
import java.io.File;
import static io.restassured.RestAssured.given;

public class RestAssured_SOAPDemo {

    File requestBody;
    Response response;

    @Test
    public void test() {

        requestBody = new File(getClass().getClassLoader().getResource("Number.xml").getFile());
        response = given()
                .baseUri("http://www.dneonline.com")
                .basePath("/calculator.asmx")
                .header("Content-Type", "text/xml; charset=utf-8")
                .body(requestBody)
                .post();

        System.out.println(response.prettyPrint());

        var xPathResult = response.xmlPath().get("//SubtractResult/text()");
        var result = Integer.parseInt(String.valueOf(xPathResult));

        System.out.println("xPathResult :" + xPathResult);
        System.out.println("result :" + result);

        Assert.assertEquals(200, response.statusCode());
        Assert.assertEquals(13, result);
    }

}

The below image shows the test result of the above test.

Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!! Cheers!!