Did you know? Research improves critical thinking skills.

Scenario-Based API Automation Interview Questions & Answers

Scenario Based API Automation Interview Questions

Scenario-Based API Automation Interview Questions & Answers

1. Login API gives token. How will you use it in next API?

First call login API and extract token. Then pass token in header of next API. Response res = given() .body(loginPayload) .post("/login"); String token = res.jsonPath().getString("token"); given() .header("Authorization","Bearer " + token) .get("/profile");

2. Create user API → Get user API → Delete user API (chaining). How will you automate?

Extract userId from create API and use it in next APIs. int id = given() .body(userPayload) .post("/users") .jsonPath().getInt("id"); given().get("/users/" + id); given().delete("/users/" + id);

3. API returns dynamic date/time. How will you validate?

Validate format, not exact value. .then().body("createdAt", matchesPattern("\\d{4}-\\d{2}-\\d{2}.*"));

4. API response has 1000 records. How will you validate?

Validate count and important fields. .then().body("data.size()", equalTo(1000));

5. How to automate negative scenario (invalid token)?

Pass wrong token and validate error. given() .header("Authorization","Bearer wrongtoken") .get("/users") .then().statusCode(401);

6. File upload API – how will you automate?

Use multipart request. given() .multiPart("file", new File("test.pdf")) .post("/upload") .then().statusCode(200);

7. API is slow sometimes. How do you validate performance?

Validate response time. .then().time(lessThan(2000L));

8. Response JSON is complex (nested). How to validate?

Use JSON path. .then().body("data.user.address.city", equalTo("Hyderabad"));

9. API depends on DB data. How will you test?

Fetch data from DB and compare with API response.

10. API allows only 5 requests per minute. How will you test?

Send 6th request and expect rate limit error (429).

11. How do you automate pagination?

Loop through pages. for(int i=1;i<=5;i++){ given().queryParam("page",i).get("/users"); }

12. API returns null for some fields. How to validate?

Validate null. .then().body("data.middleName", nullValue());

13. API returns array of users. Validate specific user present.

.then().body("data.name", hasItem("John"));

14. How to automate PUT vs PATCH scenario?

PUT replaces full object. PATCH updates single field.

15. How to validate headers?

.then().header("Content-Type","application/json");

16. API returns 200 but wrong data. What will you do?

Fail test based on business logic validation.

17. How to test DELETE API?

Delete record and try GET again (should be 404).

18. How to automate authentication with OAuth?

Call token API → get token → use in header.

19. How do you log request and response?

given().log().all().get("/users").then().log().all();

20. Explain your real project API automation flow.

Login → token → create data → validate → delete → report.



Source: sureshtechlabs.com


Share this post:

WhatsApp Facebook Twitter Telegram