Test Overview
This test uses a base test class to set up and tear down the Selenium WebDriver. It verifies that the homepage title is correct after navigating to the website.
This test uses a base test class to set up and tear down the Selenium WebDriver. It verifies that the homepage title is correct after navigating to the website.
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import static org.junit.jupiter.api.Assertions.assertEquals; public class BaseTest { protected WebDriver driver; @BeforeEach public void setUp() { driver = new ChromeDriver(); driver.manage().window().maximize(); } @AfterEach public void tearDown() { if (driver != null) { driver.quit(); } } } public class HomePageTest extends BaseTest { @Test public void testHomePageTitle() { driver.get("https://example.com"); String title = driver.getTitle(); assertEquals("Example Domain", title); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and BaseTest setUp() method runs | Chrome browser opens and window is maximized | - | PASS |
| 2 | HomePageTest navigates to https://example.com | Browser loads the Example Domain homepage | - | PASS |
| 3 | HomePageTest retrieves the page title | Page title is 'Example Domain' | Verify page title equals 'Example Domain' | PASS |
| 4 | HomePageTest assertion checks title equality | Title matches expected value | assertEquals("Example Domain", title) | PASS |
| 5 | BaseTest tearDown() method runs | Browser closes | - | PASS |