Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to initialize multiple RestAssured url in the same project without overriding each other?

Tags:

rest-assured

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.

like image 911
Vikas Avatar asked May 24 '15 17:05

Vikas


1 Answers

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.

like image 194
Johan Avatar answered Sep 22 '22 23:09

Johan