Test Overview
This test opens a browser in headless mode, navigates to a webpage, finds a heading element, and verifies its text content.
This test opens a browser in headless mode, navigates to a webpage, finds a heading element, and verifies its text content.
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; 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 HeadlessTest { private WebDriver driver; @BeforeEach public void setUp() { ChromeOptions options = new ChromeOptions(); options.addArguments("--headless=new"); driver = new ChromeDriver(options); } @Test public void testHeadingText() { driver.get("https://example.com"); WebElement heading = driver.findElement(By.tagName("h1")); assertEquals("Example Domain", heading.getText()); } @AfterEach public void tearDown() { if (driver != null) { driver.quit(); } } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Initialize ChromeDriver with headless option '--headless=new' | Chrome browser is configured to run without UI (headless mode) | - | PASS |
| 2 | Navigate to 'https://example.com' | Browser loads the Example Domain webpage in headless mode | - | PASS |
| 3 | Find the <h1> element on the page | The <h1> element with text 'Example Domain' is located | - | PASS |
| 4 | Assert that the heading text equals 'Example Domain' | Heading text is retrieved from the element | Verify heading.getText() == 'Example Domain' | PASS |
| 5 | Close the browser and quit the driver | Browser session ends cleanly | - | PASS |