0

I'm expecting an error on a server for this request, I'm going to compare it then as a string with expected response.

return given()
                .queryParams(incorrectParams)
                .when()
                .put("https://example.com/endpoint")
                .then()
                .statusCode(500)
                .extract().body().as(String.class)

The issue is that RestAssured gives me an error when executing this: java.lang.IllegalStateException: Cannot parse object because no supported Content-Type was specified in response. Content-Type was 'text/html;charset=ISO-8859-1'.

I've added decoder to setup but it won't help.

RestAssured.config().decoderConfig(new DecoderConfig(ContentType.HTML.withCharset(Charset.forName("ISO-8859-1"))));

The type returned by server in error case is: Content-Type: text/html;charset=ISO-8859-1

I additionally had seen in debbuger that default decoder should support such responses.

One more thing to mention - if request is send with correct parameters in queryParams then Content-Type: application/json is returned and everything goes fine for positive test cases.

How to handle (extract) such a response correctly? What should be set up on a Rest Assured side?

Rest-assured version is 4.4.0

2 Answers 2

1

Just to save response as String, you can do this.

.then()
.statusCode(500)
.extract().asString()
1
  • 1
    That helped me to save response as a String without error, but did not help with correct decoding. I had ' instead of ' symbol. What actually helped with correct decoding was .extract().body().asPrettyString() , however I believe that there should be more appropriate way to solve the issue
    – Kiryl K
    Sep 14, 2021 at 9:01
0

What helped me with correct decoding was

                .extract().body().asPrettyString();

However I believe that there should be more appropriate way to solve the issue.

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.