Test Overview
This test simulates a tester approaching a simple login form to verify if the login button is enabled only when both username and password fields are filled. It checks the tester's mindset of exploring positive and negative scenarios.
This test simulates a tester approaching a simple login form to verify if the login button is enabled only when both username and password fields are filled. It checks the tester's mindset of exploring positive and negative scenarios.
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 TestLoginButton(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/login') def test_login_button_enabled_only_with_input(self): driver = self.driver wait = WebDriverWait(driver, 10) username = wait.until(EC.presence_of_element_located((By.ID, 'username'))) password = wait.until(EC.presence_of_element_located((By.ID, 'password'))) login_button = wait.until(EC.presence_of_element_located((By.ID, 'login-btn'))) # Initially, login button should be disabled self.assertFalse(login_button.is_enabled(), 'Login button should be disabled initially') # Enter username only username.send_keys('user1') self.assertFalse(login_button.is_enabled(), 'Login button should remain disabled with only username') # Enter password password.send_keys('pass1') self.assertTrue(login_button.is_enabled(), 'Login button should be enabled when both fields are filled') def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and browser opens Chrome | Chrome browser window opens and navigates to https://example.com/login | - | PASS |
| 2 | Waits until username input field is present | Login page loaded with username, password fields and login button visible | Username field is present | PASS |
| 3 | Checks that login button is initially disabled | Login button is visible but disabled | Assert login button is not enabled | PASS |
| 4 | Enters 'user1' into username field | Username field contains 'user1', password field empty, login button still disabled | Assert login button remains disabled | PASS |
| 5 | Enters 'pass1' into password field | Both username and password fields filled, login button enabled | Assert login button is enabled | PASS |
| 6 | Test ends and browser closes | Browser window closes | - | PASS |