Test Overview
This test opens a web page, finds a button by its ID, clicks it, and verifies that a confirmation message appears.
This test opens a web page, finds a button by its ID, clicks it, and verifies that a confirmation message appears.
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; 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 ClickActionTest { private WebDriver driver; private WebDriverWait wait; @BeforeEach public void setUp() { driver = new ChromeDriver(); wait = new WebDriverWait(driver, 10); } @Test public void testButtonClickShowsMessage() { driver.get("https://example.com/click-test"); WebElement button = wait.until(ExpectedConditions.elementToBeClickable(By.id("click-button"))); button.click(); WebElement message = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("confirmation-message"))); assertEquals("Button clicked!", message.getText()); } @AfterEach public void tearDown() { if (driver != null) { driver.quit(); } } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Chrome browser window is open and ready | - | PASS |
| 2 | Navigates to URL https://example.com/click-test | Page loads with a button having id 'click-button' | - | PASS |
| 3 | Waits until button with id 'click-button' is clickable and finds it | Button is visible and enabled for clicking | Checks button is clickable | PASS |
| 4 | Clicks the button | Button is clicked, triggering page action | - | PASS |
| 5 | Waits until confirmation message with id 'confirmation-message' is visible | Confirmation message appears on the page | Checks message is visible | PASS |
| 6 | Verifies the confirmation message text equals 'Button clicked!' | Message text is displayed as expected | assertEquals("Button clicked!", message.getText()) | PASS |
| 7 | Test ends and browser closes | Browser window is closed | - | PASS |