本文介绍了如何在REST中确保通过默认解析器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用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 :-

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中确保通过默认解析器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 04:23