Is there a possibility of using REST Assured library for testing SOAP webservices? I have a bunch of Test Suites in SOAP UI and I need to check if there is possibility of using REST Assured. Can anyone suggest if this is possible? Many thanks for any comments.

up vote 1 down vote accepted

REST-assured does not have direct support for testing SOAP services, but it is possible by manually setting the SOAPAction and Content-Type headers and doing an HTTP POST etc. Then you can run XPath assertions on the response like you do for normal REST services in REST-assured.

I suggest you also evaluate Karate as it has built-in support for SOAP, and also makes XML manipulation a lot easier.

Yes, it is possible, however not necessarily easy.

SOAP Web service is (usually) receiving HTTP requests with XML in the body and sending back HTTP responses with XML in the body.

REST-assured can send HTTP requests with any content, including XML. It can also verify XML in responses with GPath.

Here's an example from REST-assured site:

Imagine that a POST request to http://localhost:8080/greetXML returns:

<greeting>
   <firstName>{params("firstName")}</firstName>
   <lastName>{params("lastName")}</lastName>
</greeting>

i.e. it sends back a greeting based on the firstName and lastName parameter sent in the request. You can easily perform and verify e.g. the firstName with REST assured:

given().
         parameters("firstName", "John", "lastName", "Doe").
when().
         post("/greetXML").
then().
         body("greeting.firstName", equalTo("John")).

The problem is that SOAP Requests and SOAP Responses are usually far more complex and you will need to understand WSDL descriptors yourself.

Yes it is possible.I have written this code and it is working form me:

created a file SoapRequestFile.xml with the content:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:GetConversionRate>
         <!--Optional:-->
         <tem:CurrencyFrom>USD</tem:CurrencyFrom>
         <!--Optional:-->
         <tem:CurrencyTo>INR</tem:CurrencyTo>
         <tem:RateDate>2018-12-07</tem:RateDate>
      </tem:GetConversionRate>
   </soapenv:Body>
</soapenv:Envelope>

Then here is code i have written in eclipse:

@Test
public void postMethod() throws Exception {


        FileInputStream fileInputStream = new FileInputStream(new File(".\\SOAPRequest\\SoapRequestFile.xml"));
         RestAssured.baseURI="http://currencyconverter.kowabunga.net";

         Response response=given()
                .header("Content-Type", "text/xml")
                .and()
                .body(IOUtils.toString(fileInputStream,"UTF-8"))
         .when()
            .post("/converter.asmx")
         .then()
                .statusCode(200)
                .and()
                .log().all()
                .extract().response();

        XmlPath jsXpath= new XmlPath(response.asString());//Converting string into xml path to assert
        String rate=jsXpath.getString("GetConversionRateResult");
        System.out.println("rate returned is: " +  rate);


}
New contributor
Ramani_naresh is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.