Knowledgebase

Load Testing a SOAP API


Background

Scripting example on how to load test SOAP APIs.


SOAP

Althought k6 doesn’t have any builtin APIs for working with SOAP or XML data in general, you can still easily load test a SOAP based API by crafting SOAP messages and using the HTTP request APIs.

Making SOAP requests

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import http from "k6/http";
import { check, sleep } from "k6";

const soapReqBody = `
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hs="http://www.holidaywebservice.com/HolidayService_v2/">
    <soapenv:Body>
        <hs:GetHolidaysAvailable>
            <hs:countryCode>UnitedStates</hs:countryCode>
        </hs:GetHolidaysAvailable>
    </soapenv:Body>
</soapenv:Envelope>`;

export default function() {
    // When making a SOAP POST request we must not forget to set the content type to text/xml
    let res = http.post(
        "http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx?wsdl",
        soapReqBody,
        {headers: { 'Content-Type': 'text/xml' }});

    // Make sure the response is correct
    check(res, {
        'status is 200': (r) => r.status === 200,
        'black friday is present': (r) => r.body.indexOf('BLACK-FRIDAY') !== -1
    });

    sleep(1);
}