javacitrus-framework

Is it possbile to get the content type of a http-response as String by using the Citrus-Framwork?


I'm currently trying to test a small application that returns the sum of two numbers. For testing I use Citrus. Is it possible to read the content of the respons?

The code below sends a request to the server and the server responds well. Everything works fine, but I want to know exactly what the server returns.

runner.http(action -> action.client(httpClient)
.send()
.get("?value1=1&value2=2"));


runner.http(httpActionBuilder -> httpActionBuilder
.client(httpClient)
.receive()
.response(HttpStatus.OK));

Solution

  • Besides giving the expected Http response code in the receive action you can also provide the expected message body as payload in the receive action. Just use the payload() methods on receive action builder right after response().

    Citrus will automatically verify the response body content (Json, XML, plaintext) with the expected payload. If there are unexpected differences the test will fail.

    Hope that helps.