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.
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.
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}'")
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Browser opened at https://example.com/login showing login form with username, password fields and login button | - | PASS |
| 2 | Find username, password fields and login button elements | Elements located on the page | - | PASS |
| 3 | Clear username and password fields, enter 'user1' and 'pass1' | Username field contains 'user1', password field contains 'pass1' | - | PASS |
| 4 | Check if login button is enabled | Login button is enabled because both fields are filled | Assert login button enabled is True | PASS |
| 5 | Clear fields, enter 'user2' and 'pass2' | Username field contains 'user2', password field contains 'pass2' | - | PASS |
| 6 | Check if login button is enabled | Login button is enabled | Assert login button enabled is True | PASS |
| 7 | Clear fields, enter empty username '' and password 'pass3' | Username field empty, password field contains 'pass3' | - | PASS |
| 8 | Check if login button is enabled | Login button is disabled because username is empty | Assert login button enabled is False | PASS |
| 9 | Clear fields, enter username 'user4' and empty password '' | Username field contains 'user4', password field empty | - | PASS |
| 10 | Check if login button is enabled | Login button is disabled because password is empty | Assert login button enabled is False | PASS |
| 11 | Test ends and browser closes | Browser closed | - | PASS |