Selenium API Development & Integration 3 — Questions and Answers
Question 1: In Selenium WebDriver, which interface method can be used to intercept and modify network requests to simulate API failures during testing?
- driver.manage().addCookie()
- driver.executeScript()
- DevTools CDP network interception (Correct answer)
- driver.navigate().to()
Correct answer: DevTools CDP network interception
Chrome DevTools Protocol (CDP) network interception allows Selenium tests to intercept, block, or modify HTTP requests to simulate API failures.
Question 2: What is 'API mocking' in the context of Selenium test automation?
- Writing negative test cases for APIs
- Replacing real API calls with simulated responses during testing (Correct answer)
- Documenting API endpoints with Swagger
- Load testing APIs with multiple concurrent requests
Correct answer: Replacing real API calls with simulated responses during testing
API mocking replaces actual backend API calls with predefined fake responses, allowing tests to run without depending on live backend services.
Question 3: When a Selenium test needs to verify that clicking a button triggers a specific API call, which tool approach is most effective?
- Reading the page source after the click
- Capturing network traffic via browser proxy or CDP (Correct answer)
- Checking the browser's title bar
- Inspecting local storage values
Correct answer: Capturing network traffic via browser proxy or CDP
Capturing network traffic through a proxy like BrowserMob or using Chrome DevTools Protocol allows verification that specific API calls were made.
Question 4: Which Selenium utility helps capture API request/response data by acting as a proxy between the browser and the server?
- Selenium Grid
- BrowserMob Proxy (Correct answer)
- Selenium IDE
- RemoteWebDriver
Correct answer: BrowserMob Proxy
BrowserMob Proxy sits between the browser and server, capturing all HTTP traffic including API requests and responses for assertion.
Question 5: In API integration testing with Selenium, what does 'response deserialization' mean?
- Encrypting API response data for security
- Converting a JSON/XML response string into a usable Java object (Correct answer)
- Sending test data to the API endpoint
- Validating the API response status code
Correct answer: Converting a JSON/XML response string into a usable Java object
Deserialization converts the raw JSON or XML string from an API response into a structured Java (or other language) object for easy assertion.
Question 6: When should you prefer API-level teardown over UI-level teardown in a Selenium test?
- When you need to take a screenshot of the deletion
- When teardown speed and reliability matter more than testing the delete UI (Correct answer)
- When the API does not support DELETE operations
- When the application requires manual approval for deletion
Correct answer: When teardown speed and reliability matter more than testing the delete UI
API-level teardown is faster and more reliable for cleaning up test data since it bypasses potentially flaky UI interactions.
Question 7: What is the purpose of using a 'service virtualization' tool in a Selenium API integration testing strategy?
- To run tests on virtual machines
- To simulate dependent APIs that are unavailable or under development (Correct answer)
- To virtualize the browser for headless testing
- To create virtual users for load testing
Correct answer: To simulate dependent APIs that are unavailable or under development
Service virtualization simulates the behavior of dependent APIs or services that are incomplete, unavailable, or too costly to access during testing.
In Selenium WebDriver, which interface method can be used to intercept and modify network requests to simulate API failures during testing?