Test Overview
This test runs a Selenium WebDriver test using Maven. It opens a browser, navigates to a website, clicks a button, and verifies the page title. The test verifies that Maven can successfully execute Selenium tests.
This test runs a Selenium WebDriver test using Maven. It opens a browser, navigates to a website, clicks a button, and verifies the page title. The test verifies that Maven can successfully execute Selenium tests.
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class MavenSeleniumTest { private WebDriver driver; @BeforeEach public void setUp() { // Assuming chromedriver is in system PATH driver = new ChromeDriver(); } @Test public void testButtonClickChangesTitle() { driver.get("https://example.com"); WebElement button = driver.findElement(By.id("start-button")); button.click(); String expectedTitle = "Welcome Page"; assertEquals(expectedTitle, driver.getTitle()); } @AfterEach public void tearDown() { if (driver != null) { driver.quit(); } } } // To run this test via Maven, use the command: // mvn test
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Maven starts test execution with 'mvn test' command | Maven initializes and compiles the test code | - | PASS |
| 2 | JUnit launches and runs the test method 'testButtonClickChangesTitle' | Test environment ready, ChromeDriver instance created | - | PASS |
| 3 | WebDriver opens Chrome browser | Chrome browser window is open and ready | - | PASS |
| 4 | WebDriver navigates to 'https://example.com' | Browser displays the example.com homepage | - | PASS |
| 5 | WebDriver finds the button with id 'start-button' | Button element is located on the page | - | PASS |
| 6 | WebDriver clicks the 'start-button' | Page updates after button click | - | PASS |
| 7 | Test asserts that the page title is 'Welcome Page' | Browser title is checked | assertEquals('Welcome Page', driver.getTitle()) | PASS |
| 8 | WebDriver closes the browser | Browser window is closed | - | PASS |
| 9 | JUnit finishes test and Maven reports success | Test suite completes with no errors | - | PASS |