10

I have multiple modules within same project which needs to communicate with entirely 2 different REST API systems. I want to use Rest Assured for both. The problem I am facing here is if I use the code for setting the baseuri (RestAssured.baseURI) it will override the previous baseURI. I tried to search how people have managed this situation. For single uri I use below:

RestAssured.baseURI = properties.getProperty("baseURI");

with the static import of RestAssured, but if I have two it overwrites the first one. Any suggestion? I didn't want to use requestspecbuilder itself to do it as below:

RequestSpecBuilder requestSpecBuilder = new RequestSpecBuilder();
        requestSpecBuilder.setAccept(ContentType.JSON);
        requestSpecBuilder.setContentType(ContentType.JSON);
        requestSpecBuilder.baseUri = url; 

as I would need to do it everytime I create a new specbuilder.

I am using Rest Assured 2.4.1. Thanks for your help in advance.

Vikas
  • 404
  • 5
  • 18

1 Answers1

14

You should create a RequestSpecification as you indicate in your second example:

RequestSpecification spec = new RequestSpecBuilder().setBaseUri(url).build();
given().spec(spec). ..

The spec can then be reusable in all tests that uses the same base uri.

Johan
  • 37,479
  • 32
  • 149
  • 237