0
0
Testing Fundamentalstesting~10 mins

Why security testing protects users in Testing Fundamentals - Test Execution Impact

Choose your learning style9 modes available
Test Overview

This test checks if the login page properly blocks access when wrong credentials are used, protecting user accounts from unauthorized access.

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 TestLoginSecurity(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.get('https://example.com/login')

    def test_invalid_login_blocks_access(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_message = WebDriverWait(driver, 10).until(
            EC.visibility_of_element_located((By.ID, 'error-msg'))
        )

        # Verify error message text
        self.assertEqual(error_message.text, 'Invalid username or password.')

    def tearDown(self):
        self.driver.quit()

if __name__ == '__main__':
    unittest.main()
Execution Trace - 8 Steps
StepActionSystem StateAssertionResult
1Test starts and opens Chrome browserBrowser window opens at 'https://example.com/login' showing login form with username, password fields and login button-PASS
2Waits for username input field to be presentLogin page fully loaded with input fields visibleUsername input field is presentPASS
3Finds username, password fields and login buttonAll required elements located on the pageElements found by ID selectorsPASS
4Enters invalid username and passwordInput fields filled with 'wronguser' and 'wrongpass'-PASS
5Clicks login buttonLogin form submitted, page processes login-PASS
6Waits for error message to appearError message element visible with text 'Invalid username or password.'Error message is visiblePASS
7Checks error message text matches expectedError message text is exactly 'Invalid username or password.'Error message text equals expected stringPASS
8Test ends and browser closesBrowser window closed-PASS
Failure Scenario
Failing Condition: If the error message does not appear or text is incorrect after invalid login attempt
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after clicking the login button with wrong credentials?
AThe password field is cleared automatically
BThe user is redirected to the homepage
CAn error message appears saying 'Invalid username or password.'
DThe login button becomes disabled
Key Result
Security testing verifies that the system properly blocks unauthorized access by checking error messages on invalid login attempts, protecting user accounts from misuse.