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.

asked Jul 7, 2017 at 12:49
2
  • 1
    I found you've asked same question here: stackoverflow.com/questions/44968999/…. Please, do not cross-post a question on multiple Stack Exchange sites. More explanation and how to migrate questions you can find here: meta.stackexchange.com/questions/64068/… Commented Jul 9, 2017 at 6:43
  • 1
    Sorry for that, I'm new at StackExchange and still learning rules here ;) Thanks for sharing link about how to cross-posting questions on Stack. Commented Jul 10, 2017 at 9:18

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);
}
Bence Kaulics
1,00712 silver badges22 bronze badges
answered Dec 8, 2018 at 11:49
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.

Bence Kaulics
1,00712 silver badges22 bronze badges
answered Jul 9, 2017 at 6:55
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.

answered Jul 7, 2017 at 13:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.