How to pass default parser in REST Assured?

落花浮王杯 提交于 2021-01-06 16:31:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!