0
0
Selenium Pythontesting~10 mins

Parameterized tests in Selenium Python - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens a simple login page and tries multiple username and password combinations. It verifies if the login button is enabled for each set of inputs.

Test Code - unittest
Selenium Python
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 TestLoginParameterized(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.driver = webdriver.Chrome()
        cls.driver.get('https://example.com/login')

    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()

    def test_login_button_enabled(self):
        test_data = [
            ("user1", "pass1"),
            ("user2", "pass2"),
            ("", "pass3"),
            ("user4", "")
        ]
        for username, password in test_data:
            username_field = WebDriverWait(self.driver, 10).until(
                EC.presence_of_element_located((By.ID, "username"))
            )
            password_field = self.driver.find_element(By.ID, "password")
            login_button = self.driver.find_element(By.ID, "loginBtn")

            username_field.clear()
            username_field.send_keys(username)
            password_field.clear()
            password_field.send_keys(password)

            # Check if login button is enabled
            is_enabled = login_button.is_enabled()

            # Assert login button is enabled only if both fields are non-empty
            expected = bool(username and password)
            self.assertEqual(is_enabled, expected, f"Failed for username='{username}' and password='{password}'")
Execution Trace - 11 Steps
StepActionSystem StateAssertionResult
1Test starts and Chrome browser opensBrowser opened at https://example.com/login showing login form with username, password fields and login button-PASS
2Find username, password fields and login button elementsElements located on the page-PASS
3Clear username and password fields, enter 'user1' and 'pass1'Username field contains 'user1', password field contains 'pass1'-PASS
4Check if login button is enabledLogin button is enabled because both fields are filledAssert login button enabled is TruePASS
5Clear fields, enter 'user2' and 'pass2'Username field contains 'user2', password field contains 'pass2'-PASS
6Check if login button is enabledLogin button is enabledAssert login button enabled is TruePASS
7Clear fields, enter empty username '' and password 'pass3'Username field empty, password field contains 'pass3'-PASS
8Check if login button is enabledLogin button is disabled because username is emptyAssert login button enabled is FalsePASS
9Clear fields, enter username 'user4' and empty password ''Username field contains 'user4', password field empty-PASS
10Check if login button is enabledLogin button is disabled because password is emptyAssert login button enabled is FalsePASS
11Test ends and browser closesBrowser closed-PASS
Failure Scenario
Failing Condition: Login button enabled state does not match expected when username or password is empty
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify for each username and password pair?
AIf the username field accepts numbers only
BIf the login button is always disabled
CIf the login button is enabled only when both fields are filled
DIf the password field is hidden
Key Result
Parameterized tests help check multiple input cases in one test, making testing efficient and thorough.