0
0
Testing Fundamentalstesting~10 mins

Security testing basics in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
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.

Test Code - Selenium with unittest
Testing Fundamentals
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()
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test starts and Chrome browser opensBrowser window is open and ready-PASS
2Browser navigates to 'https://example.com/secure'Browser loads the secure page URL-PASS
3Waits up to 10 seconds for element with ID 'login-form' to appearPage redirects or shows login form if unauthorizedPresence of login form elementPASS
4Finds element with ID 'login-form' and checks if it is visibleLogin form is displayed on the pageAssert login form is displayedPASS
5Test ends and browser closesBrowser window is closed-PASS
Failure Scenario
Failing Condition: The secure page does not redirect unauthorized users and shows protected content instead of login form
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify when it waits for the element with ID 'login-form'?
AThat the secure page loads protected content
BThat unauthorized users see the login form
CThat the browser opens successfully
DThat the user is already logged in
Key Result
Always verify that secure pages properly restrict access by checking for login prompts or redirects when users are not authenticated.