Passing Query Parameters in RestAssuredd
3 Ways to pass Query Parameter:
Way 1:.queryParam("name", "Trivedi").queryParam("status", "active").
@Test
public void apiGetParm() {
given().log().all()
.header("Authorization", "Bearer cdf88f0e405447388b7a1a71061f130bccd5f70990e848d560bafadc196b7680")
.queryParam("name", "Trivedi").queryParam("status", "active").
when().log().all().get("/public/v2/users").then().log().all().assertThat().statusCode(200)
.contentType(ContentType.JSON);
Way 2 using dataprovider and HashMap & Put
@DataProvider
public Object[][] getapiData() {
return new Object[][] { { "Trivedi", "active", "male" },
};
}
@Test(dataProvider = "getapiData")
public void queryParamsHashmap(String name, String status, String gender) {
Map<String, String> queryParms = new HashMap<String, String>();
queryParms.put("name", name);
queryParms.put("status", status);
queryParms.put("gender", gender);
System.out.println(queryParms);
given().log().all()
.header("Authorization", "Bearer cdf88f0e405447388b7a1a71061f130bccd5f70990e848d560bafadc196b7680")
.queryParams(queryParms).when().log().all().get("/public/v2/users").then().log().all().assertThat()
.statusCode(200).contentType(ContentType.JSON);
}
Way 3:using Map.of("name", "Trivedi", "status", "active", "gender", "male");
@Test
public void QueryParmsWithMap() {
Map<String, String> mapQueryParams = Map.of("name", "Trivedi", "status", "active", "gender", "male");
given().log().all()
.headers("Authorization", "Bearer cdf88f0e405447388b7a1a71061f130bccd5f70990e848d560bafadc196b7680")
.queryParams(mapQueryParams).when().log().all().get("/public/v2/users").then().log().all().assertThat()
.statusCode(200).and().contentType(ContentType.JSON);
}
----------------
Comments
Post a Comment