Selenium API Development & Integration 2 — Questions and Answers
Question 1: When using Selenium with REST APIs, which HTTP method is most appropriate for creating a new test resource on the server?
- GET
- POST (Correct answer)
- PUT
- DELETE
Correct answer: POST
POST is the standard HTTP method used to create new resources on a server in RESTful API design.
Question 2: In a Selenium test that validates API responses, which status code indicates a successful resource creation via a POST request?
- 200 OK
- 201 Created (Correct answer)
- 204 No Content
- 301 Moved Permanently
Correct answer: 201 Created
HTTP 201 Created is the standard response code indicating a new resource was successfully created by a POST request.
Question 3: Which Java library is commonly used alongside Selenium to make REST API calls within test automation frameworks?
- JUnit
- RestAssured (Correct answer)
- Mockito
- Hamcrest
Correct answer: RestAssured
RestAssured is a popular Java library specifically designed for testing and validating REST APIs in automation frameworks.
Question 4: When integrating API calls into Selenium tests, what is the primary advantage of using APIs for test data setup instead of UI flows?
- APIs produce more accurate screenshots
- API calls are faster and more reliable than UI interactions (Correct answer)
- APIs automatically generate test reports
- APIs eliminate the need for assertions
Correct answer: API calls are faster and more reliable than UI interactions
Using APIs for test data setup is significantly faster than navigating through the UI and avoids flaky UI-dependent preconditions.
Question 5: In Selenium test automation, what does the term 'API contract testing' refer to?
- Testing that API calls return responses within a defined time limit
- Verifying that an API adheres to its documented interface specification (Correct answer)
- Testing APIs only in production environments
- Ensuring APIs are secured with OAuth tokens
Correct answer: Verifying that an API adheres to its documented interface specification
API contract testing verifies that an API conforms to its defined specification, ensuring both provider and consumer agree on the interface.
Question 6: Which approach allows a Selenium test to bypass the UI login flow by obtaining an authentication token via API before the test starts?
- Cookie injection after API login (Correct answer)
- Hard-coding credentials in the test
- Using a proxy to intercept login requests
- Disabling authentication in the browser
Correct answer: Cookie injection after API login
Calling the authentication API to get a session token and then injecting it as a cookie allows Selenium to skip the UI login flow entirely.
Question 7: When testing a GraphQL API endpoint with Selenium's test suite, what is the primary difference from testing a REST API?
- GraphQL uses UDP instead of HTTP
- GraphQL sends all requests to a single endpoint with a query body (Correct answer)
- GraphQL requires XML payloads
- GraphQL does not support authentication
Correct answer: GraphQL sends all requests to a single endpoint with a query body
GraphQL uses a single endpoint and specifies the required data shape through a query or mutation in the request body, unlike REST's multiple resource endpoints.
When using Selenium with REST APIs, which HTTP method is most appropriate for creating a new test resource on the server?