Test Overview
This test opens a web page, finds a button by its ID, clicks it, and verifies that a confirmation message appears.
This test opens a web page, finds a button by its ID, clicks it, and verifies that a confirmation message appears.
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 ClickActionTest(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/click-test') def test_click_button_shows_message(self): driver = self.driver # Wait until the button is clickable button = WebDriverWait(driver, 10).until( EC.element_to_be_clickable((By.ID, 'click-me')) ) button.click() # Wait for the confirmation message to appear message = WebDriverWait(driver, 10).until( EC.visibility_of_element_located((By.ID, 'confirmation')) ) self.assertEqual(message.text, 'Button clicked!') def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Browser window is open, ready to load the page | - | PASS |
| 2 | Navigates to 'https://example.com/click-test' | Page loads with a button having ID 'click-me' | - | PASS |
| 3 | Waits until the button with ID 'click-me' is clickable | Button is visible and interactable | Button element is found and clickable | PASS |
| 4 | Clicks the button | Button is clicked, triggering page action | - | PASS |
| 5 | Waits until the confirmation message with ID 'confirmation' is visible | Confirmation message appears on the page | Confirmation message element is visible | PASS |
| 6 | Checks that the confirmation message text equals 'Button clicked!' | Message text is 'Button clicked!' | message.text == 'Button clicked!' | PASS |
| 7 | Test ends and browser closes | Browser window is closed | - | PASS |