degath
degath

Reputation: 1621

REST ASSURED TEST creating my own given() method

I have more than two similar REST ASSURED rests e.g.

 @Test
 public void makeSureThatGoogleIsUp() {
     given().auth().oauth2(getToken()).contentType("application/json")
     .when()
     .get("http://www.google.com")
     .then()
     .statusCode(200);
 }

 @Test
 public void makeSureThatGoogleIsUp() {
     given().auth().oauth2(getToken()).contentType("application/json")
     .when()
     .get("https://stackoverflow.com")
     .then()
     .statusCode(200);
 }

And I would've like to create method called given() to make method less complex and readable.

private [something] given(){
    return given().auth().oauth2(getToken()).contentType("application/json")
}

making my methods use my given instead of rest assured one:

 @Test
 public void makeSureThatGoogleIsUp() {
     given()
     .when()
     .get("http://www.google.com")
     .then()
     .statusCode(200);
 }

 @Test
 public void makeSureThatGoogleIsUp() {
     given()
     .when()
     .get("https://stackoverflow.com")
     .then()
     .statusCode(200);
 }

something like here: but I dont really know what kind of return type this method could have or if its even possible. Sorry, question can be trival, but seriously I'm stuck here. Any helps? Thanks! :)

Upvotes: 1

Views: 640

Answers (1)

Timothy T.
Timothy T.

Reputation: 1101

It returns a RequestSpecification object: http://static.javadoc.io/com.jayway.restassured/rest-assured/2.4.1/com/jayway/restassured/specification/RequestSpecification.html

Also a side note if you're creating your own given() -- it might be better to name the method something else as someone else using it might assume it's the jayway version and confuse themselves when they get errors.

Upvotes: 2

Related Questions