0
0
Testing Fundamentalstesting~10 mins

Authentication testing in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if a user can successfully log in with valid credentials and verifies that the welcome message appears after login.

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

    def test_valid_login(self):
        driver = self.driver
        username_input = WebDriverWait(driver, 10).until(
            EC.presence_of_element_located((By.ID, 'username'))
        )
        username_input.send_keys('validUser')

        password_input = driver.find_element(By.ID, 'password')
        password_input.send_keys('validPass123')

        login_button = driver.find_element(By.ID, 'login-button')
        login_button.click()

        welcome_message = WebDriverWait(driver, 10).until(
            EC.visibility_of_element_located((By.ID, 'welcome-msg'))
        )
        self.assertEqual(welcome_message.text, 'Welcome, validUser!')

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

if __name__ == '__main__':
    unittest.main()
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test starts and opens Chrome browserBrowser window opens at 'https://example.com/login' showing login form with username and password fields-PASS
2Waits for username input field to be present and enters 'validUser'Username input field is visible and filled with 'validUser'-PASS
3Finds password input field and enters 'validPass123'Password input field is visible and filled with 'validPass123'-PASS
4Finds and clicks the login buttonLogin button clicked, page starts loading user dashboard-PASS
5Waits for welcome message to be visibleWelcome message element with text 'Welcome, validUser!' is visible on the pageCheck that welcome message text equals 'Welcome, validUser!'PASS
6Test ends and browser closesBrowser window closes-PASS
Failure Scenario
Failing Condition: Welcome message does not appear or text is incorrect after login
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after clicking the login button?
AThat the welcome message with correct username appears
BThat the login button is disabled
CThat the password field is cleared
DThat the browser navigates to the homepage URL
Key Result
Always wait explicitly for elements to appear before interacting or asserting to avoid flaky tests.