Test Overview
This test checks if a web application properly blocks unauthorized access to a secure page. It verifies that users without login credentials cannot view protected content.
This test checks if a web application properly blocks unauthorized access to a secure page. It verifies that users without login credentials cannot view protected content.
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 TestUnauthorizedAccess(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.implicitly_wait(5) def test_access_secure_page_without_login(self): driver = self.driver driver.get('https://example.com/secure') # Wait for redirect or error message WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, 'login-form')) ) login_form = driver.find_element(By.ID, 'login-form') self.assertTrue(login_form.is_displayed(), 'Login form should be visible') 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 | Browser navigates to 'https://example.com/secure' | Browser loads the secure page URL | - | PASS |
| 3 | Waits up to 10 seconds for element with ID 'login-form' to appear | Page redirects or shows login form if unauthorized | Presence of login form element | PASS |
| 4 | Finds element with ID 'login-form' and checks if it is visible | Login form is displayed on the page | Assert login form is displayed | PASS |
| 5 | Test ends and browser closes | Browser window is closed | - | PASS |