Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
11.5k views
by Contributing Tester (78 points)
retagged by
This is the api link for get the list.

http://localhost:8000/api/employeeManagement/employee/employeeList

In rest assured, I have not passed the authorization header. So i get the message as 'Unauthorized'.So How to pass the authorization header(token) in rest assured.

How to extract the token from login api and pass it to this employee list.

1 Answer

0 like 0 dislike
by The go-to Tester (142 points)
Try  this code,

@Test
public void Login() {

    Response resp = given().header("Authorization", "Bearer "+token).
            post("http://localhost:8000/api/employeeManagement/employee/employeeList");
    System.out.println(resp.asString());
}
by Contributing Tester (78 points)
Sir, this is my code
RestAssured.baseURI = "http://10.0.0.153:8000/api/employeeManagement/employee";
 RequestSpecification httpRequest = RestAssured.given();
           
httpRequest.header("Authorization", "Bearer " + token);
 Response response = httpRequest.request(Method.GET, "/employeeList");
String responseBody = response.getBody().asString();
System.out.println("Response for List: " + response.body().asString());
I cannot pass directly your code.If i enter your code
(i).The method given() is undefined for the  type
(ii).token cannot be resolved to a variable


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...