Why automation accelerates testing in Testing Fundamentals - Automation Benefits in Action
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 LoginPage: def __init__(self, driver): self.driver = driver self.email_input = (By.ID, 'email') self.password_input = (By.ID, 'password') self.login_button = (By.ID, 'login-btn') def login(self, email, password): WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(self.email_input)).clear() self.driver.find_element(*self.email_input).send_keys(email) self.driver.find_element(*self.password_input).clear() self.driver.find_element(*self.password_input).send_keys(password) self.driver.find_element(*self.login_button).click() class DashboardPage: def __init__(self, driver): self.driver = driver self.welcome_message = (By.ID, 'welcome-msg') self.logout_button = (By.ID, 'logout-btn') def is_loaded(self): return WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(self.welcome_message)) def logout(self): WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable(self.logout_button)).click() class TestLoginAutomation(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/login') self.login_page = LoginPage(self.driver) self.dashboard_page = DashboardPage(self.driver) def test_login_multiple_users(self): users = [ ('user1@example.com', 'Password123!'), ('user2@example.com', 'Password123!'), ('user3@example.com', 'Password123!'), ('user4@example.com', 'Password123!'), ('user5@example.com', 'Password123!'), ('user6@example.com', 'Password123!'), ('user7@example.com', 'Password123!'), ('user8@example.com', 'Password123!'), ('user9@example.com', 'Password123!'), ('user10@example.com', 'Password123!') ] for email, password in users: self.driver.get('https://example.com/login') self.login_page.login(email, password) self.assertIn('/dashboard', self.driver.current_url, f'URL after login for {email} should contain /dashboard') self.assertTrue(self.dashboard_page.is_loaded(), f'Dashboard welcome message should be visible for {email}') self.dashboard_page.logout() def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
This script uses Selenium WebDriver with Python's unittest framework to automate login tests for multiple users.
The LoginPage and DashboardPage classes follow the Page Object Model to keep locators and actions organized.
Explicit waits ensure elements are ready before interacting, avoiding flaky tests.
The test test_login_multiple_users loops through 10 user credentials, logging in and verifying the dashboard loads each time.
Assertions check the URL and presence of the welcome message to confirm successful login.
Logout is performed after each login to reset state.
This automation runs much faster than manual testing, showing how automation accelerates testing.
Now add data-driven testing with 3 different sets of user credentials using unittest subTest or pytest parameterization.