Test Overview
This test automates opening a web page using Selenium with Java and verifies the page title. It shows why Selenium with Java is popular: easy browser control and reliable checks.
This test automates opening a web page using Selenium with Java and verifies the page title. It shows why Selenium with Java is popular: easy browser control and reliable checks.
import org.openqa.selenium.WebDriver; 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 SeleniumJavaTest { WebDriver driver; @BeforeEach public void setUp() { // Set path to chromedriver executable if needed driver = new ChromeDriver(); } @Test public void testOpenPageAndCheckTitle() { driver.get("https://example.com"); String title = driver.getTitle(); assertEquals("Example Domain", title); } @AfterEach public void tearDown() { if (driver != null) { driver.quit(); } } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and ChromeDriver is initialized | Chrome browser window opens, ready for commands | - | PASS |
| 2 | Navigate to https://example.com using driver.get() | Browser loads the Example Domain page | - | PASS |
| 3 | Retrieve page title with driver.getTitle() | Page title is 'Example Domain' | Check if title equals 'Example Domain' | PASS |
| 4 | Close browser with driver.quit() | Browser window closes | - | PASS |