def __init__(self, page) -> None:
super().__init__(page)
# Fields have normal labels, so I look for them the same way a user sees them,
# not by id or CSS class, which a layout designer can rename at any moment
self.username_input = page.get_by_label("Username")
self.password_input = page.get_by_label("Password")
self.login_button = page.get_by_role("button", name="Login")
# The form is needed to check that we haven't navigated away in negative tests
self.login_form = page.locator("form#login")
# The flash message, it is the same for success and error
self.flash_message = page.locator("#flash")
def fill_credentials(self, username: str, password: str):
self.username_input.fill(username)
self.password_input.fill(password)
return self
def login(self, username: str, password: str) -> SecurePage:
"""