Search code examples
javaeclipseapirest-assuredrest-assured-jsonpath

How can I get the API response in TestNG using Rest Assured to print out line by line?


I created a program to get an API response from a URL.

But for some reason it's printing it out in one long line. Is there any way to print it out the way I see it in postman? I guess what I mean is if there is a way to see the response from the API server printed out line by line instead of one long line.

    ResponseBody body = response.getBody();
    System.out.println("Response Body is: " + body.asString());

The server response is

[RemoteTestNG] detected TestNG version 6.13.1
Status code is 200
Response Body is: 
 {"request_id":"Z36ec5ee76a4788bfe83655edbbe9f0","status":"OK","data":{ONE LONG STRING OF DATA WITH NO END IN SIGHT!} 

Solution

  • You can use prettyPrint method of Response class. Status you will have to print.