Exception in thread “main” io.restassured.path.json.exception.JsonPathException: Failed to parse the JSON document while trying to “automate an API ”

徘徊边缘 提交于 2021-01-29 06:17:34

问题


I am getting the following exception while trying to Automate an API: Exception in thread "main" io.restassured.path.json.exception.JsonPathException: Failed to parse the JSON document at io.restassured.path.json.JsonPath$ExceptionCatcher.invoke(JsonPath.java:1002) at io.restassured.path.json.JsonPath$4.doParseWith(JsonPath.java:967) at io.restassured.path.json.JsonPath$JsonParser.parseWith(JsonPath.java:1047) at io.restassured.path.json.JsonPath.toJsonString(JsonPath.java:1064) at io.restassured.path.json.JsonPath.prettify(JsonPath.java:685) at io.restassured.path.json.JsonPath.prettyPrint(JsonPath.java:700) at ApiAutomation_BDD.ApiAutomation_BDD.bearerToken_GETRequest.main(bearerToken_GETRequest.java:35) Caused by: groovy.json.JsonException: Lexing failed on line: 2, column: 1, while reading '<', no possible valid JSON value or punctuation could be recognized. at groovy.json.JsonLexer.nextToken(JsonLexer.java:86) at groovy.json.JsonLexer$nextToken.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:130) at 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) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:171) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:185) at io.restassured.internal.path.json.ConfigurableJsonSlurper.parseText(ConfigurableJsonSlurper.groovy:83) at io.restassured.path.json.JsonPath$4$1.method(JsonPath.java:965) at io.restassured.path.json.JsonPath$ExceptionCatcher.invoke(JsonPath.java:1000) ... 6 more

and the following is the code which I tried (again not sharing any values coz of security risk):

public static void main(String args[]) throws IOException  {
RestAssured.baseURI = "{Url}";
RequestSpecification httpRequest = RestAssured.given()
                                   .contentType("x-www-form-urlencoded")
                                   .formParam("grant_type", "")
                                   .formParam("client_id", "") 
                                   .formParam("scope", "")
                                   .formParam("client_secret","");
    Response response = httpRequest.request(Method.GET);
    JsonPath res = response.jsonPath();
    //String BearerToken = response.getBody().asString();
    //System.out.println("The response is:" +res);
    res.prettyPrint();
    int code = response.getStatusCode();
    System.out.println("The status code is" + code);
    assertEquals(code, 200);

} }

来源:https://stackoverflow.com/questions/65578133/exception-in-thread-main-io-restassured-path-json-exception-jsonpathexception

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