Skip to content

How To Use Soap In Postman

API Testing Blog

Getting Started with SOAP in Postman

Postman, widely known for REST API testing, also provides powerful tools to handle SOAP requests. Let’s explore a step-by-step guide on how to use SOAP with Postman.

1. Setting up the SOAP Request

1.1 Create a New Request:

  • Open Postman and click “New” to create a new request.
  • Select the “POST” method for your request.

1.2 Add the SOAP Endpoint:

  • In the “Request URL” field, enter the complete SOAP endpoint URL. For example: http://www.webservicex.net/globalweather.asmx

1.3 Set Headers:

  • Click on the “Headers” tab and add the following essential header:
    • Key: Content-Type
    • Value: text/xml; charset=utf-8

1.4 Configure the Body:

  • Go to the “Body” tab and select the “raw” option.
  • Choose “XML” for the syntax highlighting.
  • Paste the SOAP request XML within the body. Here’s an example for getting weather information:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetWeather xmlns="http://www.webservicex.net/">
<CityName>London</CityName>
<CountryName>UK</CountryName>
</GetWeather>
</soap:Body>
</soap:Envelope>

2. Validating SOAP Responses

2.1 Understanding SOAP Responses:

  • SOAP responses typically come in XML format.
  • Postman automatically parses XML responses, making data extraction easy.

2.2 Examining the Response Body:

  • After sending the request, switch to the “Body” tab within the response.
  • The response XML will be displayed, allowing you to inspect the data returned by the server.

3. Utilizing Pre-Request Scripts for Dynamic SOAP Requests

3.1 Adding a Pre-Request Script:

  • Click the “Pre-request Script” tab.
  • Use JavaScript to programmatically modify the SOAP request before sending it.

3.2 Example Pre-Request Script for Parameterization:

// Set the city and country dynamically
pm.environment.set("cityName", "New York");
pm.environment.set("countryName", "USA");
// Modify the SOAP body with the dynamic values
let soapBody = pm.request.body.raw();
soapBody = soapBody.replace("London", pm.environment.get("cityName"));
soapBody = soapBody.replace("UK", pm.environment.get("countryName"));
pm.request.body.raw(soapBody);

4. Creating Test Scripts for SOAP Requests

  • 4.1 Understanding Postman Test Scripts:

    • Postman’s test scripts run after every request, allowing you to validate the response data.
    • JavaScript is used for writing test scripts.
  • 4.2 Example Test Script for a SOAP Response:

    // Extract the temperature from the response XML
    let temperature = pm.response.text().match(/<Temperature>(.*?)<\/Temperature>/)[1];
    // Check if the temperature is a valid number
    pm.test('Verify Temperature', () => {
    pm.expect(temperature).to.be.a('number');
    });
    // Assert that the temperature is below a certain limit
    pm.test('Temperature Limit', () => {
    pm.expect(temperature).to.be.below(30);
    });

5. Automating SOAP Tests with Collections

  • 5.1 Understanding Postman Collections:

    • Collections are powerful for grouping related requests and managing multiple test cases.
  • 5.2 Creating a SOAP Collection:

    • Click on the ”+ Create” button next to “Collections” in the left sidebar.
    • Name your collection, for example, “SOAP Weather API.”
  • 5.3 Adding Requests to the Collection:

    • Drag and drop the SOAP request you’ve created into the collection.
    • Add more requests as needed to comprehensively test your SOAP API.
  • 5.4 Run the Collection and Review Results:

    • Click the “Run” button on the collection.
    • Postman will execute all requests within the collection.
    • Review test results and debug any failures.

6. Advanced Techniques for SOAP in Postman

  • 6.1 Using WSDL (Web Services Description Language):

    • Postman can automatically generate requests from WSDL, simplifying the process of setting up SOAP calls.
    • Click the “Import” button in the Postman sidebar.
    • Select “WSDL” and paste the WSDL URL.
  • 6.2 Utilizing the SOAP UI Plugin:

    • To integrate Postman with the popular SOAP client tool, SoapUI, use the “SOAP UI” plugin.
    • Install the plugin from the Postman marketplace.
    • Find and use the SOAP UI related functionalities within Postman.

With these practical tips and steps, you can seamlessly leverage Postman’s features for robust SOAP API testing. Remember, integrating pre-request scripts, test scripts, and collections is key to creating efficient and scalable SOAP test workflows.

API Testing Blog