Test Overview
This test opens a browser, navigates to a website, finds the page title element, and checks if the title text is correct.
This test opens a browser, navigates to a website, finds the page title element, and checks if the title text is correct.
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 FirstSeleniumTest { private WebDriver driver; @BeforeEach public void setUp() { // Set path to chromedriver executable if needed driver = new ChromeDriver(); } @Test public void testPageTitle() { driver.get("https://example.com"); WebElement titleElement = driver.findElement(By.tagName("h1")); String titleText = titleElement.getText(); assertEquals("Example Domain", titleText); } @AfterEach public void tearDown() { if (driver != null) { driver.quit(); } } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and ChromeDriver instance is created | Browser window opens, blank page | - | PASS |
| 2 | Browser navigates to https://example.com | Browser shows Example Domain page with heading 'Example Domain' | - | PASS |
| 3 | Find element by tag name 'h1' | Element found with text 'Example Domain' | - | PASS |
| 4 | Get text from the found element | Text retrieved: 'Example Domain' | - | PASS |
| 5 | Assert that the text equals 'Example Domain' | Text matches expected value | assertEquals("Example Domain", titleText) | PASS |
| 6 | Close browser and quit driver | Browser window closes | - | PASS |