0
0
Selenium Javatesting~20 mins

Base test class pattern in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Base Test Class Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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());
    }
}
A
Example Domain
Setup started
Setup completed
Driver closed
B
Setup started
Example Domain
Setup completed
Driver closed
C
Setup started
Setup completed
Driver closed
Example Domain
D
Setup started
Setup completed
Example Domain
Driver closed
Attempts:
2 left
💡 Hint
Remember the order of execution for @BeforeEach, test method, and @AfterEach in JUnit.
assertion
intermediate
1: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");
    }
}
AassertNull(driver.getTitle());
BassertTrue(driver.getTitle().contains("Example"));
CassertFalse(driver.getTitle().contains("Example"));
DassertEquals(driver.getTitle(), "Example");
Attempts:
2 left
💡 Hint
Check which assertion matches the requirement to verify the title contains a substring.
🔧 Debug
advanced
2: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();
    }
}
AMissing @Test annotation on setUp method causes it not to run.
BNot initializing driver in the constructor causes NullPointerException.
CUsing driver.close() instead of driver.quit() causes the browser process to remain open, leading to resource leaks.
DUsing driver.quit() in tearDown causes the browser to close too early.
Attempts:
2 left
💡 Hint
Consider the difference between driver.close() and driver.quit() in Selenium.
framework
advanced
2: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?
AUse a factory method that reads browser type from a config file and returns the appropriate WebDriver instance.
BHardcode ChromeDriver initialization in the base class constructor.
CInitialize WebDriver in each test method separately for flexibility.
DUse a static WebDriver instance shared across all tests without reinitialization.
Attempts:
2 left
💡 Hint
Think about maintainability and flexibility for running tests on different browsers.
🧠 Conceptual
expert
1: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?
ATo centralize common setup and teardown code, reducing duplication and improving maintainability.
BTo write all test cases in a single class for simplicity.
CTo avoid using any test framework annotations like @BeforeEach or @AfterEach.
DTo force all tests to run sequentially without parallel execution.
Attempts:
2 left
💡 Hint
Think about how base classes help organize repeated code.