Test Overview
This test opens a web page, clicks a button, and checks if a success message appears. It verifies that the test result is correctly reported as pass or fail.
This test opens a web page, clicks a button, and checks if a success message appears. It verifies that the test result is correctly reported as pass or fail.
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 ReportTest { WebDriver driver; @BeforeEach public void setUp() { driver = new ChromeDriver(); } @Test public void testButtonClickShowsSuccessMessage() { driver.get("https://example.com/testpage"); WebElement button = driver.findElement(By.id("submit-btn")); button.click(); WebElement message = driver.findElement(By.id("success-msg")); String actualText = message.getText(); assertEquals("Success!", actualText); } @AfterEach public void tearDown() { driver.quit(); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test framework initializes and prepares to run the test | - | PASS |
| 2 | Browser opens ChromeDriver | Chrome browser window opens, ready to navigate | - | PASS |
| 3 | Navigates to https://example.com/testpage | Page loads with a button having id 'submit-btn' and a hidden success message with id 'success-msg' | - | PASS |
| 4 | Finds element by id 'submit-btn' | Button element is located on the page | - | PASS |
| 5 | Clicks the button | Button click triggers success message to appear | - | PASS |
| 6 | Finds element by id 'success-msg' | Success message element is located and visible | - | PASS |
| 7 | Gets text from success message element | Text retrieved is 'Success!' | Check if text equals 'Success!' | PASS |
| 8 | Assertion checks if actual text equals expected 'Success!' | Assertion passes confirming the success message is correct | assertEquals("Success!", actualText) | PASS |
| 9 | Test ends and browser closes | Browser window closes, test resources cleaned up | - | PASS |