Test Overview
This test opens a web page, tries to find a button, clicks it, and verifies the result. It collects evidence by taking a screenshot after clicking. This helps debugging if the test fails.
This test opens a web page, tries to find a button, clicks it, and verifies the result. It collects evidence by taking a screenshot after clicking. This helps debugging if the test fails.
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') def test_click_button_and_verify(self): driver = self.driver wait = WebDriverWait(driver, 10) button = wait.until(EC.element_to_be_clickable((By.ID, 'submit-btn'))) button.click() driver.save_screenshot('evidence_after_click.png') message = wait.until(EC.visibility_of_element_located((By.ID, 'success-msg'))) self.assertEqual(message.text, 'Success!') 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 and ready | - | PASS |
| 2 | Navigates to 'https://example.com' | Page 'https://example.com' is loaded | - | PASS |
| 3 | Waits until button with ID 'submit-btn' is clickable | Button is visible and enabled on the page | Button is clickable | PASS |
| 4 | Clicks the button with ID 'submit-btn' | Button click triggers page action | - | PASS |
| 5 | Takes screenshot and saves as 'evidence_after_click.png' | Screenshot file created showing page after click | - | PASS |
| 6 | Waits until element with ID 'success-msg' is visible | Success message is displayed on the page | Success message is visible | PASS |
| 7 | Checks that success message text equals 'Success!' | Message text is 'Success!' | Assert message.text == 'Success!' | PASS |
| 8 | Test ends and browser closes | Browser window is closed | - | PASS |