Test Overview
This test opens a web page, clicks a button, and verifies the result using Selenium. It shows how Selenium works compared to Cypress and Playwright by tracing the test steps.
This test opens a web page, clicks a button, and verifies the result using Selenium. It shows how Selenium works compared to Cypress and Playwright by tracing the test steps.
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/button') def test_click_button(self): driver = self.driver wait = WebDriverWait(driver, 10) button = wait.until(EC.element_to_be_clickable((By.ID, 'click-me'))) button.click() message = wait.until(EC.visibility_of_element_located((By.ID, 'message'))) 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 | Chrome browser window is open and ready | - | PASS |
| 2 | Browser navigates to 'https://example.com/button' | Page with a button having id 'click-me' is loaded | - | PASS |
| 3 | Wait until button with id 'click-me' is clickable | Button is visible and enabled for clicking | Button is clickable | PASS |
| 4 | Click the button | Button is clicked, page reacts to click | - | PASS |
| 5 | Wait until message with id 'message' is visible | Message element appears on page | Message element is visible | PASS |
| 6 | Check that message text equals 'Button clicked!' | Message text is displayed as expected | message.text == 'Button clicked!' | PASS |
| 7 | Close browser and end test | Browser window closed | - | PASS |