Test Overview
This test simulates a login attempt on a website with a CAPTCHA. It verifies that the CAPTCHA is detected and the test handles it by skipping the login to avoid failure.
This test simulates a login attempt on a website with a CAPTCHA. It verifies that the CAPTCHA is detected and the test handles it by skipping the login to avoid failure.
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.common.exceptions import NoSuchElementException import unittest class TestLoginWithCaptcha(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/login') def test_login_handling_captcha(self): driver = self.driver try: captcha = driver.find_element(By.ID, 'captcha') print('CAPTCHA detected, skipping login.') self.skipTest('CAPTCHA present, manual intervention needed') except NoSuchElementException: username = driver.find_element(By.ID, 'username') password = driver.find_element(By.ID, 'password') username.send_keys('testuser') password.send_keys('password123') driver.find_element(By.ID, 'login-button').click() welcome = driver.find_element(By.ID, 'welcome-message') self.assertTrue(welcome.is_displayed()) 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 opened at https://example.com/login showing login form | - | PASS |
| 2 | Test tries to find CAPTCHA element by ID 'captcha' | Page shows login form with CAPTCHA present | Check if CAPTCHA element is found | PASS |
| 3 | CAPTCHA detected, test skips login to avoid failure | Test logs 'CAPTCHA detected, skipping login.' and skips test | Skip test due to CAPTCHA presence | PASS |
| 4 | Browser closes after test ends | Browser closed | - | PASS |