I have the below Cucumber scenario with data table. I want to set query parameters in REST Assured framework. Here we have key= at and value=${atToken} which I am trying to get runtime value instead of passing hardcoded value through data table. In the below setParams method, I am trying to match the ${atToken} using param.contains("${"), but I am not able to get the desired result. Please let me know what I need to change in this for loop.
for (String param : params.keySet()) {
if (param.contains("${")) {
params.replace(param, RUN_TIME_DATA.get(param));
}
}
Feature file:
And I set query parameters
| location | NY |
| at | ${atToken} |
Stepdefintion:
@And("set {} parameters")
public void set_query_parameters(String query, DataTable params) throws IOException {
POC.setParams(query, params.asMap());
}
Utils file:
public void setParams (String type, Map < String, String > params) throws IOException {
for (String param : params.keySet()) {
if (param.contains("${")) {
params.replace(param, RUN_TIME_DATA.get(param));
}
}
switch (type.toLowerCase()) {
case "form":
request.formParams(params);
break;
case "query":
request.queryParams(params);
break;
case "path":
request.pathParams(params);
break;
}
}
Hooks file:
@Before
public void beforeScenario() throws Exception {
RUN_TIME_DATA.put("atToken", POC.createAuth());
}