Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass authorization token in header in Rest assured?

Trying to automate api testing using Rest assured

@Test
public void Login() {
    Response resp = given().
            body("{\"phone_number\":\"2222222222\",\"\r\n" + 
                    "               + \" \"country_code\": \"+91\",\"\r\n" + 
                    "               + \" \"login_type\": 0}").
            when().
            contentType(ContentType.JSON).
            post("http://url/api/v1/login");

    System.out.println(resp.asString());
}
like image 212
Bharath S Avatar asked Sep 17 '17 13:09

Bharath S


1 Answers

Add authorization header.

Response resp = given().header("Authorization", "Bearer "+token).body(...

For more info, see here.

like image 126
Nabin Bhandari Avatar answered Sep 22 '22 14:09

Nabin Bhandari