Test Overview
This test opens a web page, clicks a button, and verifies the page title. It uses TestNG framework which generates default reports showing test pass or fail status.
This test opens a web page, clicks a button, and verifies the page title. It uses TestNG framework which generates default reports showing test pass or fail status.
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class SampleTest { WebDriver driver; @BeforeClass public void setup() { driver = new ChromeDriver(); driver.manage().window().maximize(); } @Test public void testButtonClickChangesTitle() { driver.get("https://example.com"); WebElement button = driver.findElement(By.id("changeTitleBtn")); button.click(); String expectedTitle = "Title Changed"; String actualTitle = driver.getTitle(); Assert.assertEquals(actualTitle, expectedTitle, "Page title should change after button click"); } @AfterClass public void teardown() { if (driver != null) { driver.quit(); } } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | TestNG test suite initialized | - | PASS |
| 2 | Browser opens ChromeDriver and maximizes window | Chrome browser window is open and maximized | - | PASS |
| 3 | Navigates to https://example.com | Example.com homepage is loaded | - | PASS |
| 4 | Finds button with id 'changeTitleBtn' | Button element is located on the page | - | PASS |
| 5 | Clicks the button | Page title changes to 'Title Changed' | - | PASS |
| 6 | Gets the page title | Page title is 'Title Changed' | Assert that actual title equals 'Title Changed' | PASS |
| 7 | Test method completes | TestNG records test as passed | - | PASS |
| 8 | Browser quits | Browser window closed | - | PASS |
| 9 | TestNG generates default report showing test passed | Report available in test-output folder with test status PASS | - | PASS |