I have set the URL in the serenity.config and runnig the API resquest based on the regions.All are working fine but when i want to reduce the repeated codes as i have lot of apis to automate. I tried to create a seperate class for {EnvironmentSpecificConfiguration} and tried to call in the test steps class getting null point.help me how can i reduce the code and make repeated thing in a reusable class.I am using retassured with serenity ,gradle
LocalDate today = LocalDate.now();
LocalDate tomorrow = today.plusDays(1);
LocalDate nextday = today.plusDays(2);
private EnvironmentVariables environmentVariables;
public Response response;
String basePath = "/booking/search";
@Step("user perform a GET search request current day")
public void SearchCurrentDay() {
String BASEURI = EnvironmentSpecificConfiguration.from(environmentVariables).getProperty("base.api.url");
response = SerenityRest.given().contentType("application/json")
.header("Content-Type", "application/json")
.when().queryParam("type", 2)
.queryParam("date_req", today.toString())
.queryParam("days", 1)
.queryParam("id", 1)
.get(BASEURI + basePath);
System.out.println("Search json response:::==>" + response.prettyPrint());
}
@Step("user perform a GET diary search request Tomorrow")
public void dairySearchTomorrow() {
String BASEURI = EnvironmentSpecificConfiguration.from(environmentVariables).getProperty("base.api.url");
response = SerenityRest.given().contentType("application/json")
.header("Content-Type", "application/json")
.when().queryParam("type", 2)
.queryParam("date_req", tomorrow.toString())
.get(BASEURI + basePath);
System.out.println("search json response:::==>" + response.prettyPrint());
}
@Step("user perform a GET diary search request next day")
public void dairySearchNextDay() {
String BASEURI = EnvironmentSpecificConfiguration.from(environmentVariables).getProperty("base.api.url");
response = SerenityRest.given().contentType("application/json")
.header("Content-Type", "application/json")
.when().queryParam("type", 2)
.queryParam("date_req", nextday.toString())
.get(BASEURI + basePath);
System.out.println("search json response:::==>" + response.prettyPrint());
}
}
Issue has been Resolved as I used the:
String BASEURI = EnvironmentSpecificConfiguration.from(environmentVariables).getProperty("base.api.url");
in @Before annotation to use it globally