9

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.

2

3 Answers 3

2

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);
}
2

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.

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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