Test Overview
This test opens a web page and finds the first <h1> tag element. It verifies that the text inside the <h1> tag matches the expected heading.
This test opens a web page and finds the first <h1> tag element. It verifies that the text inside the <h1> tag matches the expected heading.
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.options import Options import unittest class TestFindElementByTagName(unittest.TestCase): def setUp(self): options = Options() options.add_argument('--headless') service = Service() self.driver = webdriver.Chrome(service=service, options=options) def test_find_h1_by_tag_name(self): self.driver.get('https://example.com') element = self.driver.find_element(By.TAG_NAME, 'h1') self.assertEqual(element.text, 'Example Domain') def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test framework initializes and prepares the test environment | - | PASS |
| 2 | Browser opens in headless mode | Chrome browser instance is launched without UI | - | PASS |
| 3 | Navigates to 'https://example.com' | Browser loads the Example Domain page with a visible <h1> element | - | PASS |
| 4 | Finds element by tag name 'h1' using driver.find_element(By.TAG_NAME, 'h1') | The first <h1> element on the page is located | - | PASS |
| 5 | Checks that the text of the <h1> element equals 'Example Domain' | The element text is 'Example Domain' | assertEqual(element.text, 'Example Domain') | PASS |
| 6 | Browser closes and test ends | Browser instance is terminated cleanly | - | PASS |