【问题标题】:I am unable to post an Add Place API when using POST http method使用 POST http 方法时,我无法发布 Add Place API
【发布时间】: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


【解决方案1】:

我尝试在 pom.xml 文件中为所需的 jar 文件组合以下版本,并且它对我来说工作正常。你也可以试试:

  1. JUnit- 版本:4.1.2
  2. 黄瓜 - java - info.cukes - 版本:1.2.4
  3. 黄瓜 - junit - info.cukes - 版本:1.2.3
  4. 黄瓜 - pico 容器 - info.cukes - 版本:1.2.4
  5. 黄瓜 - 核心 - info.cukes - 版本:1.2.6
  6. Cucumber - jvm deps - info.cukes - 版本:1.0.5
  7. Rest Assurd - 版本:3.0.2

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-24
    • 2021-02-16
    • 2015-01-08
    • 2011-10-21
    • 1970-01-01
    • 2019-05-14
    • 1970-01-01
    相关资源
    最近更新 更多