Automation maintenance challenges in Testing Fundamentals - Build an Automation Script
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 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, 'loginBtn') def enter_email(self, email): WebDriverWait(self.driver, 10).until( EC.visibility_of_element_located(self.email_input) ).send_keys(email) def enter_password(self, password): WebDriverWait(self.driver, 10).until( EC.visibility_of_element_located(self.password_input) ).send_keys(password) def click_login(self): WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable(self.login_button) ).click() class DashboardPage: def __init__(self, driver): self.driver = driver self.welcome_message = (By.ID, 'welcomeMsg') def is_welcome_message_displayed(self): return WebDriverWait(self.driver, 10).until( EC.visibility_of_element_located(self.welcome_message) ) is not None def test_login(): driver = webdriver.Chrome() driver.get('https://example.com/login') login_page = LoginPage(driver) login_page.enter_email('user@example.com') login_page.enter_password('Password123') login_page.click_login() WebDriverWait(driver, 10).until( EC.url_contains('/dashboard') ) dashboard_page = DashboardPage(driver) assert dashboard_page.is_welcome_message_displayed(), 'Welcome message not displayed on dashboard' driver.quit()
This test script uses Selenium WebDriver with Python to automate the login functionality.
We use the Page Object Model to keep locators and actions organized in LoginPage and DashboardPage classes. This makes maintenance easier if UI changes.
Explicit waits ensure elements are ready before interacting, avoiding flaky tests.
Locators use stable IDs instead of brittle XPaths to reduce breakage when UI changes.
The test opens the login page, enters credentials, clicks login, waits for the dashboard URL, and asserts the welcome message is visible.
This structure helps handle automation maintenance challenges by isolating UI changes to page objects and using robust waits and locators.
Now add data-driven testing with 3 different sets of login credentials (valid and invalid).