【问题标题】:Rest Assured API testing - Pass a Json Object as parameter to a get request放心的 API 测试 - 将 Json 对象作为参数传递给 get 请求
【发布时间】:2016-03-14 05:50:31
【问题描述】:

REST 保证测试 - 如何使用删除请求从该网址删除工作区

http://in-kumaran2-1:8080/devops-workbench-web/rest/api/workspace/delete/{projectId}

根据请求

given().when().delete(url,JSON body);

示例请求 JSON 正文如下所示

{"name":"newworkspace","workspaceFlow":"打开 Sorce","versionControl":"SVN","featureManagement":"JIRA","defectManagement":"","buildAutomation":"Selenium","deploymentAutomation":"","buildRepository":"Nexus"," codeQualityTools":"SonarQube","automatedTestingTools":"Selenium","environmentProvision":"Puppet","environmentConfiguration":"Puppet","projectId":{"id":"56cebe578850d51c6fe07684","name" :"wbproject","description":"wbproject","processTemplate":"Agile","projectManager":"Anil","projectStartDate":1454284800000,"projectEndDate":1475193600000,"remarks":null,"accountId" :{"id":"56cebe218850d51c6fe07683","accountName":"workbench","accountDescription":"workbench 帐户"}}}

projectID 有另一个 Object {"id": "56cebe578850d51c6fe07684" ....} 如何在删除请求中传递这个projectId

【问题讨论】:

    标签: rest testing junit parameter-passing rest-assured


    【解决方案1】:

    实际上,我已经传递了如下的 json 对象:

    Response res =given().
                content(jo). //jo is the json object to pass with the url.
                with().
                contentType("application/json").
                header("Content-Type", "application/json").
        when().
                post(settings.getApiUrl()); //this is the url, i use post method
    

    jo 是这样的:

    JsonObject jo = new JsonObject();
    jo.addProperty("username", "abc");//key and value
    jo.addProperty("password", "abc");//key and value
    

    你可以尝试这样的事情。我在这里用作标题你可以将它作为参数发送。

    【讨论】:

      【解决方案2】:

      网址为:http://example.com/building

      我的查询字符串是:

      globalDates:{"startMs":1473672973818,"endMs":1481448973817,"period":90} 限制到:6 加载电视数据:真 开始:0 用户ID:5834fb36981baacb6a876427

      使用 Rest Assured 在 GET url 中传递查询字符串参数的方法如下:-

      when() .parameter("globalDates","startMs","1474260058054","endMs","1482036058051","period","90")

      .parameters("limitTo","6")

      .parameters("loadTvData","true")

      .parameters("startFrom","0")

      .parameters("userId","5834fb36981baacb6a876427");

      【讨论】:

        猜你喜欢
        • 2021-04-28
        • 1970-01-01
        • 1970-01-01
        • 2020-01-10
        • 1970-01-01
        • 1970-01-01
        • 2013-09-02
        • 2015-08-27
        • 1970-01-01
        相关资源
        最近更新 更多