Test Overview
This test simulates error guessing by deliberately entering invalid input to check if the system handles errors gracefully. It verifies that the application shows an appropriate error message when invalid data is submitted.
This test simulates error guessing by deliberately entering invalid input to check if the system handles errors gracefully. It verifies that the application shows an appropriate error message when invalid data is submitted.
import unittest 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 class TestErrorGuessing(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/login') def test_invalid_login(self): driver = self.driver # Find username field and enter invalid username username = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, 'username')) ) username.clear() username.send_keys('invalid_user!@#') # Find password field and enter invalid password password = driver.find_element(By.ID, 'password') password.clear() password.send_keys('wrongpass123') # Click login button login_button = driver.find_element(By.ID, 'loginBtn') login_button.click() # Wait for error message to appear error_msg = WebDriverWait(driver, 10).until( EC.visibility_of_element_located((By.ID, 'errorMessage')) ) # Assert error message text self.assertEqual(error_msg.text, 'Invalid username or password.') def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and browser opens the login page | Browser displays the login page with username, password fields and login button | - | PASS |
| 2 | Find username field and enter invalid username 'invalid_user!@#' | Username field is filled with invalid characters | - | PASS |
| 3 | Find password field and enter invalid password 'wrongpass123' | Password field is filled with invalid password | - | PASS |
| 4 | Click the login button | Login button is clicked, form is submitted | - | PASS |
| 5 | Wait for error message to appear with id 'errorMessage' | Error message element is visible on the page | Verify error message text equals 'Invalid username or password.' | PASS |