Test Overview
This test opens a web browser and navigates to a specific URL using Selenium WebDriver's driver.get() method. It verifies that the page title matches the expected title to confirm successful navigation.
This test opens a web browser and navigates to a specific URL using Selenium WebDriver's driver.get() method. It verifies that the page title matches the expected title to confirm successful navigation.
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 OpenUrlTest { private WebDriver driver; @BeforeEach public void setUp() { // Assuming chromedriver is set in system PATH driver = new ChromeDriver(); } @Test public void testOpenUrl() { 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 instance is created | Chrome browser window opens, blank page | - | PASS |
| 2 | driver.get("https://example.com") is called to open the URL | Browser navigates to https://example.com, page loads | - | PASS |
| 3 | driver.getTitle() retrieves the page title | Page title is 'Example Domain' | assertEquals("Example Domain", title) verifies the title matches expected | PASS |
| 4 | driver.quit() is called to close the browser | Browser window closes | - | PASS |