HomeBlog ArticlesAbout Me

Testing SOAP WebServices using REST-Assured Library

By Aby Thannikal Joseph
Published in Test Automation
December 27, 2022
1 min read
Testing SOAP WebServices using REST-Assured Library

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 manualcheck

wsdl soapaction addinteger

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


   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().

ide code output

References



Tags

testautomation
Previous Article
Authentication for Azure REST APIs using Azure AD Service Principals
Aby Thannikal Joseph

Aby Thannikal Joseph

Table Of Contents

1
Getting the SOAPAction value from WSDL
2
REST-Assured code for SOAP Call
3
References
Aby Thannikal Joseph © 2022, All Rights Reserved.

Legal Stuff

Privacy NoticeCookie PolicyTerms Of Use

Social Media