Test Overview
This test opens a web page, finds a button, clicks it, and verifies that a message appears. It shows how interacting with elements drives what we test.
This test opens a web page, finds a button, clicks it, and verifies that a message appears. It shows how interacting with elements drives what we test.
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 TestButtonClick(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/buttonpage') def test_button_click_shows_message(self): driver = self.driver wait = WebDriverWait(driver, 10) button = wait.until(EC.element_to_be_clickable((By.ID, 'show-message-btn'))) button.click() message = wait.until(EC.visibility_of_element_located((By.ID, 'message'))) self.assertEqual(message.text, 'Hello, you clicked the button!') def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and opens Chrome browser | Browser window opens at 'https://example.com/buttonpage' | - | PASS |
| 2 | Waits until button with ID 'show-message-btn' is clickable | Page loaded with button visible and enabled | Button is clickable | PASS |
| 3 | Clicks the button | Button clicked, page reacts by showing a message | - | PASS |
| 4 | Waits until message with ID 'message' is visible | Message element appears on page | Message text equals 'Hello, you clicked the button!' | PASS |
| 5 | Test ends and browser closes | Browser window closed | - | PASS |