Challenge - 5 Problems
Base Test Class Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Base Test Class Setup
Consider the following Java Selenium base test class snippet. What will be the output when the test method runs?
Selenium Java
public class BaseTest { protected WebDriver driver; @BeforeEach public void setUp() { System.out.println("Setup started"); driver = new ChromeDriver(); driver.get("https://example.com"); System.out.println("Setup completed"); } @AfterEach public void tearDown() { driver.quit(); System.out.println("Driver closed"); } } public class SampleTest extends BaseTest { @Test public void testTitle() { System.out.println(driver.getTitle()); } }
Attempts:
2 left
💡 Hint
Remember the order of execution for @BeforeEach, test method, and @AfterEach in JUnit.
✗ Incorrect
The @BeforeEach method runs first, printing 'Setup started' and 'Setup completed'. Then the test method runs, printing the page title 'Example Domain'. Finally, @AfterEach runs, printing 'Driver closed'.
❓ assertion
intermediate1:30remaining
Correct Assertion in Base Test Class
In a base test class, which assertion correctly verifies that the page title contains the word "Example" after navigation?
Selenium Java
public class BaseTest { protected WebDriver driver; @BeforeEach public void setUp() { driver = new ChromeDriver(); driver.get("https://example.com"); } }
Attempts:
2 left
💡 Hint
Check which assertion matches the requirement to verify the title contains a substring.
✗ Incorrect
assertTrue with contains("Example") correctly checks if the title includes the word 'Example'. assertEquals would fail because the full title is not exactly 'Example'.
🔧 Debug
advanced2:00remaining
Identify the Bug in Base Test Class Setup
What is the main issue in this base test class setup code that causes tests to fail intermittently?
Selenium Java
public class BaseTest { protected WebDriver driver; @BeforeEach public void setUp() { driver = new ChromeDriver(); driver.get("https://example.com"); } @AfterEach public void tearDown() { driver.close(); } }
Attempts:
2 left
💡 Hint
Consider the difference between driver.close() and driver.quit() in Selenium.
✗ Incorrect
driver.close() closes only the current window but leaves the browser process running. driver.quit() closes all windows and ends the browser process, preventing resource leaks.
❓ framework
advanced2:30remaining
Best Practice for WebDriver Initialization in Base Test Class
Which approach is best for initializing WebDriver in a base test class to support multiple browsers?
Attempts:
2 left
💡 Hint
Think about maintainability and flexibility for running tests on different browsers.
✗ Incorrect
A factory method reading from config allows easy switching between browsers without code changes. Hardcoding or static instances reduce flexibility and can cause test interference.
🧠 Conceptual
expert1:30remaining
Purpose of Base Test Class in Selenium Framework
What is the primary purpose of using a base test class pattern in Selenium test automation?
Attempts:
2 left
💡 Hint
Think about how base classes help organize repeated code.
✗ Incorrect
Base test classes hold shared setup and cleanup logic so individual test classes can focus on test logic, avoiding code repetition and easing maintenance.