How to pass default parser in REST Assured?

12.3k views Asked by At

I am trying to Automate API using REST Assured. Below is the Error I got in during executing the API Test Case :-

testNotifications(com.api.truValue.test.notifications.NotificationsTest) Time elapsed: 1.832 sec <<< FAILURE!

java.lang.IllegalStateException:

Cannot invoke the path method because no content-type was present in the response and no default parser has been set.

You can specify a default parser using e.g.: RestAssured.defaultParser = Parser.JSON;

at com.api.truValue.test.notifications.NotificationsTest.testNotifications(NotificationsTest.java:35)

Please let me know how to resolve this or How to Pass Default Parser.

1

There are 1 answers

0
Adam On

The answer to your question is in the error you received: You can specify a default parser using e.g.: RestAssured.defaultParser = Parser.JSON;

When setting up RestAssured, add the following line: RestAssured.defaultParser = Parser.JSON;

Alternatively, and probably better, the service you are testing should populate the content-type header in its responses.