问题
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:
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.
来源:https://stackoverflow.com/questions/41234485/how-to-pass-default-parser-in-rest-assured