Selenium Testing Framework Case Studies & Practical Application 5 — Questions and Answers
Question 1: A Selenium test for a single-page application (SPA) clicks a link that updates the view without changing the URL. The next page's content doesn't load in the assertion. The fix is:
- Use driver.navigate().to() to force navigation
- Wait for a stale element exception then re-locate the target element
- Wait for a unique element on the new view to become present (Correct answer)
- Refresh the browser after the click
Correct answer: Wait for a unique element on the new view to become present
In SPAs, URL-based waits don't work; waiting for a unique element specific to the new view confirms the navigation rendered successfully.
Question 2: A test team wants to ensure their Selenium tests run on the same browser version as their users. The best infrastructure practice is:
- Always use the latest browser beta version
- Pin browser versions in CI and use Selenium Manager or WebDriverManager for version matching (Correct answer)
- Let each developer install whatever browser they prefer
- Only run tests on Firefox as it's most stable
Correct answer: Pin browser versions in CI and use Selenium Manager or WebDriverManager for version matching
Pinning browser versions and using a driver manager ensures consistent, reproducible test environments that match the targeted user browser.
Question 3: After switching to headless Chrome for CI, a test that submits a form fails only in headless mode. The most likely cause is:
- Headless Chrome doesn't support JavaScript
- The form submit button is outside the default viewport in headless mode (Correct answer)
- Headless mode uses a different WebDriver protocol
- CSS transitions don't work in headless mode
Correct answer: The form submit button is outside the default viewport in headless mode
Headless Chrome defaults to a small viewport (800x600), causing elements positioned below the fold to be non-interactable; setting an explicit window size resolves this.
Question 4: A team wants to implement test reporting that shows which user stories are covered by automated tests. The best approach is:
- Add story IDs as comments in test code
- Tag test methods with story IDs and integrate with a reporting tool like Allure or ExtentReports (Correct answer)
- Maintain a separate spreadsheet mapping tests to stories
- Use test method names to encode story IDs
Correct answer: Tag test methods with story IDs and integrate with a reporting tool like Allure or ExtentReports
Tagging tests with story IDs and using a reporting tool creates automated traceability between tests and requirements without manual maintenance.
Question 5: A Selenium test must handle a session timeout scenario where the app shows a 'Session Expired' modal after 30 minutes of inactivity. The best way to test this without waiting 30 minutes is:
- Set the system clock forward 30 minutes
- Directly expire the session via an API call or cookie manipulation, then trigger an action (Correct answer)
- Wait 30 minutes in the test
- Reduce the session timeout to 1 second in production config
Correct answer: Directly expire the session via an API call or cookie manipulation, then trigger an action
Programmatically expiring the session via API or clearing/modifying the session cookie lets you test the timeout scenario instantly without modifying production configuration.
Question 6: A Selenium test suite uses a shared WebDriver instance across all tests in a class. Tests start failing with 'element not interactable' errors after one test opens a popup. The fix is:
- Restart the browser before every test class
- Ensure each test closes any popups or modal dialogs it opens as teardown (Correct answer)
- Use a new WebDriver instance per test method
- Add implicit waits globally to compensate
Correct answer: Ensure each test closes any popups or modal dialogs it opens as teardown
Proper teardown that closes popups prevents test pollution where UI state from one test causes the next test to interact with unexpected overlays.
Question 7: A team needs to test that their web application is accessible to keyboard-only users as part of their Selenium suite. The most practical approach is:
- Disable the mouse driver during test execution
- Use sendKeys(Keys.TAB) to navigate and Keys.ENTER/SPACE to interact, asserting focus order
- Only hire QA testers who use keyboard navigation
- Use an accessibility scanner like axe-core via JavascriptExecutor (Correct answer)
Correct answer: Use an accessibility scanner like axe-core via JavascriptExecutor
Integrating axe-core via JavascriptExecutor provides comprehensive accessibility checks including keyboard accessibility, ARIA compliance, and contrast ratios in a single automated step.
A Selenium test for a single-page application (SPA) clicks a link that updates the view without changing the URL.
The next page's content doesn't load in the assertion.
The fix is: