Selenium Testing Framework Case Studies & Practical Application 4 — Questions and Answers
Question 1: A Selenium test suite runs against multiple browsers (Chrome, Firefox, Edge). Currently the browser is hard-coded in a base class. The best architectural change is:
- Create a separate test suite per browser
- Read the browser type from a configuration file or environment variable (Correct answer)
- Use if/else statements per test method
- Only test on Chrome to reduce complexity
Correct answer: Read the browser type from a configuration file or environment variable
Reading browser type from configuration or environment variables allows the same tests to run against any browser without code changes.
Question 2: After a sprint, 30% of automated tests are failing due to UI redesign (locators changed). To prevent this recurring cost, the team should:
- Delete and rewrite failing tests each sprint
- Implement data-testid attributes with developers and update locators once per change (Correct answer)
- Switch to image-based testing tools
- Only run tests before UI changes are deployed
Correct answer: Implement data-testid attributes with developers and update locators once per change
Stable data-testid attributes agreed upon with developers create resilient locators that don't break with styling or layout changes.
Question 3: A test must verify that a search returns exactly 10 results on the first page. The results load asynchronously. The most reliable assertion approach is:
- Assert immediately after triggering the search
- Wait for the result count element to appear, then assert the list size (Correct answer)
- Thread.sleep(3000) then count list items
- Assert the URL contains '?page=1'
Correct answer: Wait for the result count element to appear, then assert the list size
Waiting for a specific element that signals results have loaded before asserting the count ensures the DOM is stable.
Question 4: A team wants to run Selenium tests on mobile browsers. The most appropriate tool to extend their existing Selenium setup is:
- Sikuli for image recognition
- Appium, which extends the WebDriver protocol for mobile (Correct answer)
- Robot Framework only
- BrowserStack with manual configuration only
Correct answer: Appium, which extends the WebDriver protocol for mobile
Appium implements the WebDriver protocol for mobile platforms, allowing teams to reuse Selenium skills and some code for mobile browser testing.
Question 5: A Selenium test navigates to a page with infinite scroll. To test that items load when scrolling, the best approach is:
- Resize the browser window to show all items
- Use JavascriptExecutor to scroll to the bottom and wait for new elements (Correct answer)
- Click a 'Load More' button if one exists, else skip
- Use driver.manage().window().maximize()
Correct answer: Use JavascriptExecutor to scroll to the bottom and wait for new elements
Scrolling via JavascriptExecutor (window.scrollTo or element.scrollIntoView) triggers the scroll events that activate infinite scroll loaders.
Question 6: A test verifies that a user with read-only permissions cannot see the 'Delete' button. The test logs in, navigates to the resource, and asserts. After deployment, this test starts failing intermittently. The most likely cause is:
- The Delete button is now visible to all users
- A race condition where the permissions API response arrives after the assertion (Correct answer)
- The login mechanism changed
- The button ID changed in the new build
Correct answer: A race condition where the permissions API response arrives after the assertion
If the UI renders before permissions are loaded, the Delete button may briefly appear then hide, causing the assertion to catch it in an intermediate state.
Question 7: A company uses Selenium for regression testing and wants to add visual regression testing to catch CSS regressions. The best complementary approach is:
- Compare page source HTML strings between runs
- Integrate a visual comparison tool like Applitools Eyes or Percy alongside Selenium (Correct answer)
- Take manual screenshots after each deployment
- Write CSS assertions using getCssValue() for every element
Correct answer: Integrate a visual comparison tool like Applitools Eyes or Percy alongside Selenium
Visual testing tools like Applitools integrate with Selenium to capture and diff screenshots automatically, catching pixel-level CSS regressions that functional tests miss.
A Selenium test suite runs against multiple browsers (Chrome, Firefox, Edge).
Currently the browser is hard-coded in a base class.
The best architectural change is: