如何在 REST Assured 中传递默认解析器? [英] How to pass default parser in REST Assured?
问题描述
我正在尝试使用 REST Assured 自动化 API.以下是我在执行 API 测试用例时遇到的错误:-
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) 已用时间:1.832 秒 <<<失败!
testNotifications(com.api.truValue.test.notifications.NotificationsTest) Time elapsed: 1.832 sec <<< FAILURE!
java.lang.IllegalStateException:
java.lang.IllegalStateException:
无法调用 path 方法,因为响应中不存在内容类型且未设置默认解析器.
Cannot invoke the path method because no content-type was present in the response and no default parser has been set.
您可以使用例如指定默认解析器:RestAssured.defaultParser = Parser.JSON;
You can specify a default parser using e.g.: RestAssured.defaultParser = Parser.JSON;
在 com.api.truValue.test.notifications.NotificationsTest.testNotifications(NotificationsTest.java:35)
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.
推荐答案
您的问题的答案在您收到的错误中:您可以使用例如指定默认解析器:RestAssured.defaultParser = Parser.JSON;代码>
The answer to your question is in the error you received: You can specify a default parser using e.g.: RestAssured.defaultParser = Parser.JSON;
在设置 RestAssured 时,添加以下行:RestAssured.defaultParser = Parser.JSON;
When setting up RestAssured, add the following line: RestAssured.defaultParser = Parser.JSON;
或者,可能更好的是,您正在测试的服务应该在其响应中填充 content-type
标头.
Alternatively, and probably better, the service you are testing should populate the content-type
header in its responses.
这篇关于如何在 REST Assured 中传递默认解析器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!