0
0
Testing Fundamentalstesting~10 mins

Page Object Model concept in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if the login page works correctly using the Page Object Model (POM) design. It verifies that a user can enter a username and password, click the login button, and see the welcome message.

Test Code - Selenium
Testing Fundamentals
class LoginPage:
    def __init__(self, driver):
        self.driver = driver
        self.username_input = "#username"
        self.password_input = "#password"
        self.login_button = "#loginBtn"
        self.welcome_message = "#welcomeMsg"

    def enter_username(self, username):
        self.driver.find_element("css selector", self.username_input).send_keys(username)

    def enter_password(self, password):
        self.driver.find_element("css selector", self.password_input).send_keys(password)

    def click_login(self):
        self.driver.find_element("css selector", self.login_button).click()

    def get_welcome_text(self):
        return self.driver.find_element("css selector", self.welcome_message).text


def test_login_success(driver):
    login_page = LoginPage(driver)
    driver.get("https://example.com/login")
    login_page.enter_username("testuser")
    login_page.enter_password("password123")
    login_page.click_login()
    welcome_text = login_page.get_welcome_text()
    assert welcome_text == "Welcome, testuser!"
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test starts and browser opensBrowser window is open but no page loaded yet-PASS
2Navigate to https://example.com/loginLogin page is loaded with username, password fields and login button visiblePage URL is https://example.com/loginPASS
3Find username input field and enter 'testuser'Username field contains 'testuser'Username input value is 'testuser'PASS
4Find password input field and enter 'password123'Password field contains 'password123' (masked)Password input value is 'password123'PASS
5Find and click the login buttonPage processes login and loads welcome message-PASS
6Find welcome message element and get its textWelcome message displayed: 'Welcome, testuser!'Welcome message text equals 'Welcome, testuser!'PASS
Failure Scenario
Failing Condition: Welcome message text does not match expected text after login
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after clicking the login button?
AThat the username field is cleared
BThat the login button disappears
CThat the welcome message shows 'Welcome, testuser!'
DThat the password is visible
Key Result
Using the Page Object Model helps keep test code clean and easy to maintain by separating page details from test logic.