BaseTest
BaseTest (Selenium4Java)
This class is responsible for initializing and managing the Selenium test environment.Tests are executed on a remote Selenium Grid / Testinium Grid using TestiniumSeleniumDriver. Its main responsibilities include:
- Initializing the RemoteWebDriver for the test run
- Configuring browser-specific options (e.g., ChromeOptions)
- Providing a shared driver instance for test execution
- Handling test lifecycle operations
- Ensuring proper cleanup of resources after execution completes
All driver lifecycle operations are managed using JUnit 5 annotations.
@BeforeAll setup()
This method runs once before all test methods in the test class.Its responsibilities include:
- Determining the remote Selenium Grid URL(e.g. http://host.docker.internal:4444/wd/hub or via environment variables)
-
Testinium-specific capabilities can be added if required
ChromeOptions for Chrome-based executions
Creating and configuring browser options:
- Initializing the driver using TestiniumSeleniumDriver
-
Initializing WebDriverWait or FluentWait for dynamic elements
Setting implicit/explicit waits
Maximizing the browser window
Performing optional driver-level configurations:
@AfterAll teardown()
This method runs once after all test methods in the test class.Its responsibilities include:
- Quitting the WebDriver session using driver.quit()
- Releasing Selenium Grid resources
- Preventing session leaks
Test Execution (@Test)
Test methods use the shared driver instance to:
- Navigate to target web pages
- Interact with UI elements
- Handle dynamic components such as cookie consent dialogs
- Validate application behavior using JUnit assertions
Example test actions include:
- Searching for a keyword on a search engine
- Verifying the visibility of result containers
- Asserting page titles and expected content