How to pass Query String Parameters in GET url using Rest Assured?

泄露秘密 提交于 2019-12-07 06:40:22

问题


How to pass Query String Parameters in GET url using Rest Assured?

URL is: http://example.com/building

My Query Strings are :

globalDates:{"startMs":1473672973818,"endMs":1481448973817,"period":90}
limitTo:6
loadTvData:true
startFrom:0
userId:5834fb36981baacb6a876427

回答1:


You can pass them as a queryParam ..

given()
.queryParam("globalDates", "{\"startMs\":1473672973818,\"endMs\":1481448973817,\"period\":90}")
.queryParam("startFrom", "0").queryParam("limitTo", "6").queryParam("loadTvData", true)
.queryParam("startFrom", "0").queryParam("userId", "5834fb36981baacb6a876427")
.when().get("http://example.com/building"). ...



回答2:


And also you can put this queryparams in Map like follows,

HashMap<String, String> params = new HashMap<String, String>() {{

put("globalDates", "{\"startMs\":1473672973818,\"endMs\":1481448973817,\"period\":90}");

put("limitTo","6" );

,...

}}

And post it like follows,

 resp = RestAssured.given()
                    .headers(headers)
                    .queryParameters(params)
                    .post(apiURL).andReturn();



回答3:


You can pass query string parameters in a GET URL using Rest Assured like this :

when()
  .parameter("globalDates","startMs","1474260058054","endMs","1482036058051","period","90")                              
  .parameters("limitTo","6")                                  
  .parameters("loadTvData","true")                                
  .parameters("startFrom","0")
  .parameters("userId","5834fb36981baacb6a876427");


来源:https://stackoverflow.com/questions/41085365/how-to-pass-query-string-parameters-in-get-url-using-rest-assured

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