Tutorial · Test Automation

Testing SOAP WebServices using REST-Assured Library

REST-Assured has no native SOAPAction method. This article explores a method for using REST-Assured to send requests to SOAP services despite that limitation.

Aby Thannikal Joseph1 min read
Title card: Testing SOAP WebServices using REST-Assured Library, showing a SOAP request icon plus the REST Assured logo
In this article3 sections

REST-Assured is a library that is specifically designed for testing REST API services. However, what if you want to test both REST and SOAP API services using a single framework? Fortunately, it is possible to use REST-Assured for testing both types of APIs. Although REST-Assured supports XML format, it does not have a native SOAPAction method for sending requests to SOAP services.

In this article, we will explore a method for using REST-Assured to send requests to SOAP services despite this limitation.

Getting the SOAPAction value from WSDL

To demo, I am using a public SOAP webservice from https://www.crcind.com/csp/samples/SOAP.Demo.cls

The WSDL file is present at https://www.crcind.com/csp/samples/SOAP.Demo.CLS?WSDL=1 and is loaded into SoapUI to do a quick sanity check for sending a sample request.

SoapUI sending an AddInteger request with arguments 5 and 7 to the SOAP.Demo.cls endpoint; the response returns AddIntegerResult 7

The service WSDL in a browser with the AddInteger operation’s soapAction value, http://tempuri.org/SOAP.Demo.AddInteger, highlighted

The value of the SOAPAction field is to be noted and feeds into the header in the REST Assured call. The operation we are interested in is the addition operation and hence the http://tempuri.org/SOAP.Demo.AddInteger is copied

REST-Assured code for SOAP Call

java
   public void RESTAssuredSOAPCall() throws IOException {
        File requestBody = new File(getClass().getClassLoader().getResource("addition-requestbody.xml").getFile());
        Response response = RESTAssured.given()
                .baseUri("https://www.crcind.com:443")
                .basePath("/csp/samples/SOAP.Demo.cls")
                .header("SOAPAction", "http://tempuri.org/SOAP.Demo.AddInteger")
                .header("Content-Type", "text/xml; charset=utf-8")
                .body(requestBody)
                .post();

        assertEquals(200,response.statusCode());
        System.out.println(response.prettyPrint());
    }

The request payload is saved in the addition-requestbody.xml file which is read and passed into the body().

IntelliJ IDEA running the RestAssuredSOAPCall test: 1 of 1 test passed and the console prints a SOAP envelope containing AddIntegerResult 12

References

Written by

Aby Thannikal Joseph

Test manager in financial-services technology, with a background in test automation, Azure and DevOps. Builds practical AI applications. Microsoft Certified DevOps Engineer Expert and Azure Developer Associate.