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();
}
在此处输入图像描述 Junit 错误日志
无法识别任何可能的有效 JSON 值或标点符号。在 groovy.json.JsonLexer.nextToken(JsonLexer.java:86) 在 groovy.json.JsonLexer$nextToken.call(Unknown Source) 在 org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)在 org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) 在 org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:130) 在 io.restassured.internal.path .json.ConfigurableJsonSlurper.parse(ConfigurableJsonSlurper.groovy:97) at io.restassured.internal.path.json.ConfigurableJsonSlurper$parse.callCurrent(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray. java:51) 在 org.codehaus.groovy.runtime.callsite.AbstractCallSite。