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
CodePudding user response:
Just to save response as String, you can do this.
.then()
.statusCode(500)
.extract().asString()
CodePudding user response:
What helped me with correct decoding was
.extract().body().asPrettyString();
However I believe that there should be more appropriate way to solve the issue.