Question 5: Explain the complete flow of an API automation test using a tool like Rest Assured or Postman.
Answer:
A typical API automation test flow includes the following steps:
- Set Base URI
Define the base address of the API:
https://api.example.com - Choose HTTP Method
Decide which method (GET, POST, etc.) to use based on the test scenario. - Add Headers
Example: Content-Type: application/json, Authorization: Bearer <token> - Add Request Body (for POST/PUT/PATCH)
JSON body with relevant payload.
Send Request and Capture Response
Use code like this in Rest Assured:
java
given()
.baseUri(“https://api.example.com”)
.header(“Authorization”, “Bearer ” + token)
.contentType(“application/json”)
.body(jsonPayload)
.when()
.post(“/users”)
.then()
.statusCode(201)
.body(“id”, notNullValue());
- Assertions
Validate status codes, response body, headers, and time. - Logging and Reporting
Integrate with TestNG + Extent Reports or Postman’s Newman reports for CI/CD pipelines.
This structured approach ensures maintainability and scalability of your automation framework.