Test Overview
This test checks if the login page properly blocks access when wrong credentials are used. It verifies that the system does not allow unauthorized users to log in.
This test checks if the login page properly blocks access when wrong credentials are used. It verifies that the system does not allow unauthorized users to log in.
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 TestAuthenticationVulnerability(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/login') def test_invalid_login(self): driver = self.driver # Wait for username field WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'username'))) username_input = driver.find_element(By.ID, 'username') password_input = driver.find_element(By.ID, 'password') login_button = driver.find_element(By.ID, 'login-btn') # Enter invalid credentials username_input.send_keys('wronguser') password_input.send_keys('wrongpass') login_button.click() # Wait for error message error_element = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, 'error-msg')) ) # Verify error message text self.assertEqual(error_element.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 opens Chrome browser | Browser is open at 'https://example.com/login' page showing login form with username, password fields and login button | - | PASS |
| 2 | Waits until username input field is present | Login form is fully loaded with username input visible | Username input field is present | PASS |
| 3 | Finds username, password input fields and login button | All required elements located by their IDs | Elements found successfully | PASS |
| 4 | Enters invalid username 'wronguser' and password 'wrongpass' | Input fields filled with invalid credentials | - | PASS |
| 5 | Clicks the login button | Login form submitted, page processes login attempt | - | PASS |
| 6 | Waits for error message element with ID 'error-msg' to appear | Error message displayed on page | Error message element is present | PASS |
| 7 | Checks that error message text equals 'Invalid username or password.' | Error message text visible to user | Error message text matches expected | PASS |
| 8 | Test ends and browser closes | Browser closed, test complete | - | PASS |