Test Overview
This test opens a web page, retrieves its title and URL, and verifies they match expected values.
This test opens a web page, retrieves its title and URL, and verifies they match expected values.
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.*; public class PageTitleUrlTest { private WebDriver driver; @BeforeEach public void setUp() { driver = new ChromeDriver(); } @Test public void testPageTitleAndUrl() { driver.get("https://example.com"); String title = driver.getTitle(); String url = driver.getCurrentUrl(); assertEquals("Example Domain", title); assertEquals("https://example.com/", url); } @AfterEach public void tearDown() { if (driver != null) { driver.quit(); } } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Chrome browser window is open and ready | - | PASS |
| 2 | Navigates to https://example.com | Browser displays the Example Domain page | - | PASS |
| 3 | Retrieves page title using driver.getTitle() | Title retrieved: 'Example Domain' | Check if title equals 'Example Domain' | PASS |
| 4 | Retrieves current URL using driver.getCurrentUrl() | URL retrieved: 'https://example.com/' | Check if URL equals 'https://example.com/' | PASS |
| 5 | Assertions for title and URL pass | Test confirms title and URL are correct | assertEquals for title and URL | PASS |
| 6 | Browser closes and test ends | Browser window closed | - | PASS |