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.
from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.by import By import unittest class HeadlessBrowserTest(unittest.TestCase): def setUp(self): options = Options() options.headless = True self.driver = webdriver.Chrome(options=options) def test_heading_text(self): self.driver.get('https://example.com') heading = self.driver.find_element(By.TAG_NAME, 'h1') self.assertEqual(heading.text, 'Example Domain') def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and sets up Chrome browser in headless mode | Chrome browser is launched without UI (headless) | - | PASS |
| 2 | Browser navigates to 'https://example.com' | Page loads with heading 'Example Domain' | - | PASS |
| 3 | Finds the <h1> element on the page | Element with tag 'h1' containing text 'Example Domain' is located | - | PASS |
| 4 | Checks if the heading text equals 'Example Domain' | Heading text is 'Example Domain' | Assert heading.text == 'Example Domain' | PASS |
| 5 | Test tears down and closes the browser | Headless browser session ends | - | PASS |