0
0
Testing Fundamentalstesting~10 mins

Page Object Model concept in Testing Fundamentals - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a page object class for a login page.

Testing Fundamentals
class LoginPage:
    def __init__(self, driver):
        self.driver = driver
        self.username_field = self.driver.find_element_by_id([1])
Drag options to blanks, or click blank then click option'
A"login"
B"password"
C"submit"
D"username"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the password or submit button id instead of username.
2fill in blank
medium

Complete the method to enter text into the username field.

Testing Fundamentals
def enter_username(self, username):
    self.username_field.[1](username)
Drag options to blanks, or click blank then click option'
Aclick
Bsend_keys
Csubmit
Dclear
Attempts:
3 left
💡 Hint
Common Mistakes
Using click or submit instead of send_keys.
3fill in blank
hard

Fix the error in the method to click the login button.

Testing Fundamentals
def click_login(self):
    self.driver.find_element_by_id([1]).click()
Drag options to blanks, or click blank then click option'
A"submit"
B"login"
C"login_button"
D"button_login"
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect id names like 'login' or 'login_button'.
4fill in blank
hard

Fill both blanks to create a method that logs in with username and password.

Testing Fundamentals
def login(self, username, password):
    self.username_field.[1](username)
    self.password_field.[2](password)
Drag options to blanks, or click blank then click option'
Asend_keys
Bclick
Cclear
Dsubmit
Attempts:
3 left
💡 Hint
Common Mistakes
Using click or submit instead of send_keys for input fields.
5fill in blank
hard

Fill all three blanks to define a complete login page object with methods to enter username, password, and click login.

Testing Fundamentals
class LoginPage:
    def __init__(self, driver):
        self.driver = driver
        self.username_field = self.driver.find_element_by_id([1])
        self.password_field = self.driver.find_element_by_id([2])
        self.login_button = self.driver.find_element_by_id([3])

    def enter_username(self, username):
        self.username_field.send_keys(username)

    def enter_password(self, password):
        self.password_field.send_keys(password)

    def click_login(self):
        self.login_button.click()
Drag options to blanks, or click blank then click option'
A"username"
B"password"
C"submit"
D"login"
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up ids or using wrong element ids.