Test Overview
This test opens a browser, navigates to a simple webpage, finds a button, clicks it, and verifies the expected text appears. It shows why controlling the browser is the base for all web tests.
This test opens a browser, navigates to a simple webpage, finds a button, clicks it, and verifies the expected text appears. It shows why controlling the browser is the base for all web tests.
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import unittest class TestBrowserControl(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/testpage') def test_button_click_shows_text(self): driver = self.driver wait = WebDriverWait(driver, 10) button = wait.until(EC.element_to_be_clickable((By.ID, 'show-text-btn'))) button.click() displayed_text = wait.until(EC.visibility_of_element_located((By.ID, 'result-text'))) self.assertEqual(displayed_text.text, 'Hello, world!') def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Chrome browser window is open and ready | - | PASS |
| 2 | Browser navigates to 'https://example.com/testpage' | Page loads with a button having ID 'show-text-btn' | Page URL is correct and page loaded | PASS |
| 3 | Waits for button with ID 'show-text-btn' to be clickable and clicks it | Button is clickable and clicked | Button click triggers expected action | PASS |
| 4 | Waits for element with ID 'result-text' to be visible | Text element appears on page | Element with text 'Hello, world!' is visible | PASS |
| 5 | Checks that displayed text equals 'Hello, world!' | Text matches expected string | AssertEqual passes confirming correct text | PASS |
| 6 | Browser closes and test ends | Browser window closed | - | PASS |