0
0
Testing Fundamentalstesting~10 mins

Authentication vulnerability testing in Testing Fundamentals - Test Execution Trace

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

Test Code - Selenium with Python unittest
Testing Fundamentals
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()
Execution Trace - 8 Steps
StepActionSystem StateAssertionResult
1Test starts and opens Chrome browserBrowser is open at 'https://example.com/login' page showing login form with username, password fields and login button-PASS
2Waits until username input field is presentLogin form is fully loaded with username input visibleUsername input field is presentPASS
3Finds username, password input fields and login buttonAll required elements located by their IDsElements found successfullyPASS
4Enters invalid username 'wronguser' and password 'wrongpass'Input fields filled with invalid credentials-PASS
5Clicks the login buttonLogin form submitted, page processes login attempt-PASS
6Waits for error message element with ID 'error-msg' to appearError message displayed on pageError message element is presentPASS
7Checks that error message text equals 'Invalid username or password.'Error message text visible to userError message text matches expectedPASS
8Test ends and browser closesBrowser closed, test complete-PASS
Failure Scenario
Failing Condition: Error message element does not appear after submitting invalid credentials
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after clicking the login button with wrong credentials?
AThat the user is redirected to the homepage
BThat the password field is cleared
CThat an error message saying 'Invalid username or password.' appears
DThat the login button is disabled
Key Result
Always wait explicitly for elements that appear after actions, like error messages, to avoid flaky tests and ensure the application properly handles invalid inputs.