【发布时间】:2020-06-04 05:03:44
【问题描述】:
io.restassured.path.json.exception.JsonPathException:解析失败 JSON 文档
为这些功能文件步骤编写的代码中出现错误:
Given Add new location with "<name>" "<language>" "<address>" parameters
Then user calls "AddPlaceAPI" with http "POST" method
Then API successful response with "status" as "OK"
这些步骤的 stepDefinition 代码
@Given("Add new location with {string} {string} {string} parameters")
public void Add_new_location_with_three_parameters(String name_G,String address_G,String language_G) throws IOException {
res=given().spec(requestSpecification())
.body(data.googleAddPlace(name_G,address_G,language_G));
}
@Then("user calls {string} with http {string} method")
public void user_calls_with_http_method(String resource_G,String http_method)
{
APIResources resourceAPI = APIResources.valueOf(resource_G);
System.out.println("Resource value" + resourceAPI.getResource());
resspec =new ResponseSpecBuilder().expectStatusCode(200).expectContentType(ContentType.JSON).build();
if(http_method.equalsIgnoreCase("POST"))
response= res.when().post(resourceAPI.getResource());
else if(http_method.equalsIgnoreCase("GET"))
response= res.when().post(resourceAPI.getResource());
}
@Then("API successful response with {string} as {string}")
public void api_successful_response_with_as(String string, String string2) {
// Write code here that turns the phrase above into concrete actions
assertEquals(getJsonPath(response,string),string2);
}
getJsonPath 方法定义抛出错误的位置
public String getJsonPath(Response response,String key)
{
String resp=response.asString();
JsonPath js = new JsonPath(resp);
return js.get(key).toString();
}
enter image description here Junit 错误日志
io.restassured.path.json.exception.JsonPathException:解析 JSON 文档失败 在 io.restassured.path.json.JsonPath$ExceptionCatcher.invoke(JsonPath.java:1002) 在 io.restassured.path.json.JsonPath$4.doParseWith(JsonPath.java:967) 在 io.restassured.path.json.JsonPath$JsonParser.parseWith(JsonPath.java:1047) 在 io.restassured.path.json.JsonPath.get(JsonPath.java:202) 在 resources.Utils.getJsonPath(Utils.java:56) 在 stepDefinations.stepDefination.api_successful_response_with_as(stepDefination.java:117) 在 ✽.API 成功响应,“状态”为“OK”(file:///C:/Users/gaura/eclipse-workspaceNew/APIFramework/src/test/java/features/googlemapsValidation.feature:6) 引起:groovy.json.JsonException:Lexing 在第 1 行失败,第 1 列,在读取“
【问题讨论】:
-
解决了吗?
-
不,还没有解决。 @Willfred Clement
标签: json cucumber-jvm cucumber-junit rest-assured-jsonpath grasshopper