Rest Assured API测试 - 将Json Object作为参数传递给get请求

时间:2016-03-14 05:50:32

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

REST确保测试 - 如何使用删除请求从此网址中删除工作区

http://in-kumaran2-1:8080/devops-workbench-web/rest/api/workspace/delete/ {专案编号}

给出请求

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

下面给出了样本请求JSON正文

  

{"名称":" newworkspace"" workspaceFlow":"开   SORCE""版本控制":" SVN"" featureManagement":" JIRA"" defectManagement&#34 ;: """ buildAutomation":"硒"" deploymentAutomation":""" buildRepository& #34;:" Nexus和#34;" codeQualityTools":" SonarQube"" automatedTestingTools":"硒",& #34; environmentProvision":"木偶"" environmentConfiguration":"木偶",的"专案编号" {&# 34; ID":" 56cebe578850d51c6fe07684""名称":" wbproject""描述":" wbproject&#34 ;," processTemplate":"敏捷"" projectManager":"阿尼尔"" projectStartDate":1454284800000,& #34; projectEndDate":1475193600000,"备注":空,"帐户ID" {" ID":" 56cebe218850d51c6fe07683",& #34;帐户名":"工作台"" accountDescription":"工作台   帐户"}} }

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

2 个答案:

答案 0 :(得分: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

你可以尝试类似这样的东西。我在这里使用的标题你可以把它作为参数发送。

答案 1 :(得分:0)

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

我的查询字符串是:

globalDates:{" startMs":1473672973818," endMs":1481448973817,"周期" 90} limitTo:6 loadTvData:真 startFrom:0 用户名:5834fb36981baacb6a876427

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

when().parameter(" globalDates"," startMs"," 1474260058054"," endMs"," 1482036058051& #34;"周期"" 90&#34)

.parameters(" limitTo"" 6&#34)

.parameters(" loadTvData""真&#34)

.parameters(" startFrom"" 0&#34)

.parameters("用户id"" 5834fb36981baacb6a876427&#34);