Test Overview
This test opens a webpage with a confirmation alert, clicks a button to trigger the alert, accepts the alert, and verifies the confirmation message on the page.
This test opens a webpage with a confirmation alert, clicks a button to trigger the alert, accepts the alert, and verifies the confirmation message on the page.
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 TestConfirmationAlert(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/confirmation-alert') def test_accept_confirmation_alert(self): driver = self.driver # Click the button that triggers the confirmation alert button = WebDriverWait(driver, 10).until( EC.element_to_be_clickable((By.ID, 'confirm-btn')) ) button.click() # Wait for the alert to be present alert = WebDriverWait(driver, 10).until(EC.alert_is_present()) # Accept the confirmation alert alert.accept() # Verify the confirmation message is displayed message = WebDriverWait(driver, 10).until( EC.visibility_of_element_located((By.ID, 'confirm-message')) ) self.assertEqual(message.text, 'You clicked OK!') 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 URL https://example.com/confirmation-alert | - | PASS |
| 2 | Waits until the button with ID 'confirm-btn' is clickable | Page fully loaded with visible button 'confirm-btn' | Button is clickable | PASS |
| 3 | Clicks the 'confirm-btn' button to trigger confirmation alert | Confirmation alert appears on screen | - | PASS |
| 4 | Waits for the confirmation alert to be present | Alert dialog is present and active | Alert is present | PASS |
| 5 | Accepts the confirmation alert by clicking OK | Alert disappears, page updates accordingly | - | PASS |
| 6 | Waits for the confirmation message element with ID 'confirm-message' to be visible | Confirmation message 'You clicked OK!' is visible on the page | Message text equals 'You clicked OK!' | PASS |
| 7 | Test ends and browser closes | Browser window closed | - | PASS |