Skip to content

Commit

Permalink
Merge pull request #6305 from emilghittasv/playwright-improve-auth-page
Browse files Browse the repository at this point in the history
Playwright improve and document auth related page object & flow classes
  • Loading branch information
emilghittasv authored Oct 22, 2024
2 parents efde9ea + 5e24e0b commit 364e39f
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 46 deletions.
25 changes: 25 additions & 0 deletions playwright_tests/flows/auth_flows/auth_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,64 @@ def __init__(self, page: Page):

# Providing OTP code to FxA auth.
def __provide_otp_code(self, otp_code: str):
"""Add data to 'Enter your OTP code' input field and click on 'Submit' button
Args:
otp_code (str): OTP code to be added to the input field.
"""
self.auth_page.add_data_to_otp_code_input_field(otp_code)
self.auth_page.click_on_otp_code_confirm_button()

# Providing the needed login credentials to FxA auth.
def __provide_login_credentials_and_submit(self, username: str, password: str):
"""Provide login credentials to FxA auth and submit them.
Args:
username (str): Username to be added to the input field.
password (str): Password to be added to the input field
"""
self.auth_page.add_data_to_email_input_field(username)
self.auth_page.click_on_enter_your_email_submit_button()

if self.auth_page.is_logged_in_sign_in_button_displayed():
"""If the user the sign in button is displayed, click on it."""
self.auth_page.click_on_user_logged_in_sign_in_button()
else:
"""If the password input field is displayed, add the password to it and
click on the submit button."""
self.auth_page.add_data_to_password_input_field(password)
self.auth_page.click_on_enter_your_password_submit_button()

def login_with_existing_session(self):
"""Login with an existing session."""
if self.auth_page.is_continue_with_firefox_button_displayed():
"""If the 'Continue with Firefox Accounts' button is displayed, click on it."""
self.auth_page.click_on_continue_with_firefox_accounts_button()
self.auth_page.click_on_user_logged_in_sign_in_button()

# Sign in flow.
def sign_in_flow(self, username: str, account_password: str) -> str:
"""Sign in flow.
Args:
username (str): Username to be used for sign in.
account_password (str): Password to be used for sign in.
"""
# Forcing an email clearance
self.utilities.clear_fxa_email(username)

if self.auth_page.is_continue_with_firefox_button_displayed():
"""If the 'Continue with Firefox Accounts' button is displayed, click on it."""
self.auth_page.click_on_continue_with_firefox_accounts_button()

if self.auth_page.is_use_a_different_account_button_displayed():
"""If the 'Use a different account' button is displayed, click on it."""
self.auth_page.click_on_use_a_different_account_button()

self.__provide_login_credentials_and_submit(username, account_password)

if self.auth_page.is_enter_otp_code_input_field_displayed():
"""If the OTP code input field is displayed, provide the OTP code."""
self.__provide_otp_code(self.utilities.get_fxa_verification_code(
fxa_username=username))

Expand Down
105 changes: 59 additions & 46 deletions playwright_tests/pages/auth_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,85 +3,98 @@


class AuthPage(BasePage):

# Auth page content
__auth_page_section = "//section[@class='sumo-auth--wrap']"
__fxa_sign_in_page_header = "//h1[@id='fxa-signin-password-header']"
__auth_page_main_header = "//h1[@class='sumo-page-heading']"
__auth_page_subheading_text = "//div[@class='sumo-page-section']/p"
__cant_sign_in_to_my_Mozilla_account_link = "//div[@class='trouble-text']//a"

# Continue with firefox accounts button
__continue_with_firefox_accounts_button = "//p[@class='login-button-wrap']/a"

# Use a different account option
__use_a_different_account_button = "//a[text()='Use a different account']"

# Already logged in 'Sign in' button
__user_logged_in_sign_in_button = "//button[text()='Sign in']"

# Email submission
__enter_your_email_input_field = "//input[@name='email']"
__enter_your_email_submit_button = "//button[@id='submit-btn']"

# Password submission
__enter_your_password_input_field = "//input[@type='password']"
__enter_your_password_submit_button = "//button[text()='Sign in']"

# OTP Code
__enter_otp_code_input_field = "//input[@id='otp-code']"
__enter_otp_code_confirm_button = "//button[@id='submit-btn']"
AUTH_PAGE_CONTENT_LOCATORS = {
"auth_page_section": "//section[@class='sumo-auth--wrap']",
"fxa_sign_in_page_header": "//h1[@id='fxa-signin-password-header']",
"auth_page_main_header": "//h1[@class='sumo-page-heading']",
"auth_page_subheading_text": "//div[@class='sumo-page-section']/p",
"cant_sign_in_to_my_Mozilla_account_link": "//div[@class='trouble-text']//a",
"continue_with_firefox_accounts_button": "//p[@class='login-button-wrap']/a",
"use_a_different_account_button": "//a[text()='Use a different account']",
"user_logged_in_sign_in_button": "//button[text()='Sign in']",
"enter_your_email_input_field": "//input[@name='email']",
"enter_your_email_submit_button": "//button[@id='submit-btn']",
"enter_your_password_input_field": "//input[@type='password']",
"enter_your_password_submit_button": "//button[text()='Sign in']",
"enter_otp_code_input_field": "//input[@id='otp-code']",
"enter_otp_code_confirm_button": "//button[@id='submit-btn']"
}

def __init__(self, page: Page):
super().__init__(page)

def click_on_cant_sign_in_to_my_mozilla_account_link(self):
self._click(self.__cant_sign_in_to_my_Mozilla_account_link)
"""Click on 'Can't sign in to my Mozilla account' link"""
self._click(self.AUTH_PAGE_CONTENT_LOCATORS["cant_sign_in_to_my_Mozilla_account_link"])

def click_on_continue_with_firefox_accounts_button(self):
self._click(self.__continue_with_firefox_accounts_button)
"""Click on 'Continue with Firefox Accounts' button"""
self._click(self.AUTH_PAGE_CONTENT_LOCATORS["continue_with_firefox_accounts_button"])

def click_on_use_a_different_account_button(self):
self._click(self.__use_a_different_account_button)
"""Click on 'Use a different account' button"""
self._click(self.AUTH_PAGE_CONTENT_LOCATORS["use_a_different_account_button"])

def click_on_user_logged_in_sign_in_button(self):
self._click(self.__user_logged_in_sign_in_button)
"""Click on 'Sign in' button"""
self._click(self.AUTH_PAGE_CONTENT_LOCATORS["user_logged_in_sign_in_button"])

def click_on_enter_your_email_submit_button(self):
self._click(self.__enter_your_email_submit_button)
"""Click on 'Submit' e-mail button"""
self._click(self.AUTH_PAGE_CONTENT_LOCATORS["enter_your_email_submit_button"])

def click_on_enter_your_password_submit_button(self):
self._click(self.__enter_your_password_submit_button)
"""Click on 'Sign in' password button"""
self._click(self.AUTH_PAGE_CONTENT_LOCATORS["enter_your_password_submit_button"])

def click_on_otp_code_confirm_button(self):
self._click(self.__enter_otp_code_confirm_button)
"""Click on 'Submit' OTP code button"""
self._click(self.AUTH_PAGE_CONTENT_LOCATORS["enter_otp_code_confirm_button"])

def add_data_to_email_input_field(self, text: str):
self._fill(self.__enter_your_email_input_field, text)
"""Add data to 'Enter your email' input field"""
self._fill(self.AUTH_PAGE_CONTENT_LOCATORS["enter_your_email_input_field"], text)

def add_data_to_password_input_field(self, text: str):
self._fill(self.__enter_your_password_input_field, text)
"""Add data to 'Enter your password' input field"""
self._fill(self.AUTH_PAGE_CONTENT_LOCATORS["enter_your_password_input_field"], text)

def add_data_to_otp_code_input_field(self, text: str):
self._fill(self.__enter_otp_code_input_field, text)
"""Add data to 'Enter OTP code' input field"""
self._fill(self.AUTH_PAGE_CONTENT_LOCATORS["enter_otp_code_input_field"], text)

def clear_email_input_field(self):
self._clear_field(self.__enter_your_email_input_field)
"""Clear 'Enter your email' input field"""
self._clear_field(self.AUTH_PAGE_CONTENT_LOCATORS["enter_your_email_input_field"])

def is_use_a_different_account_button_displayed(self) -> bool:
self._wait_for_selector(self.__use_a_different_account_button)
return self._is_element_visible(self.__use_a_different_account_button)
"""Check if 'Use a different account' button is displayed"""
self._wait_for_selector(self.AUTH_PAGE_CONTENT_LOCATORS["use_a_different_account_button"],
timeout=5000)
return self._is_element_visible(self.AUTH_PAGE_CONTENT_LOCATORS
["use_a_different_account_button"])

def is_logged_in_sign_in_button_displayed(self) -> bool:
return self._is_element_visible(self.__user_logged_in_sign_in_button)
"""Check if 'Sign in' button is displayed"""
return self._is_element_visible(
self.AUTH_PAGE_CONTENT_LOCATORS["user_logged_in_sign_in_button"])

def is_enter_otp_code_input_field_displayed(self) -> bool:
self._wait_for_selector(self.__continue_with_firefox_accounts_button)
return self._is_element_visible(self.__enter_otp_code_input_field)
"""Check if 'Enter OTP code' input field is displayed"""
self._wait_for_selector(
self.AUTH_PAGE_CONTENT_LOCATORS["continue_with_firefox_accounts_button"])
return self._is_element_visible(self.AUTH_PAGE_CONTENT_LOCATORS
["enter_otp_code_input_field"])

def is_continue_with_firefox_button_displayed(self) -> bool:
self._wait_for_selector(self.__continue_with_firefox_accounts_button)
return self._is_element_visible(self.__continue_with_firefox_accounts_button)
"""Check if 'Continue with Firefox Accounts' button is displayed"""
self._wait_for_selector(self.AUTH_PAGE_CONTENT_LOCATORS
["continue_with_firefox_accounts_button"])
return self._is_element_visible(self.AUTH_PAGE_CONTENT_LOCATORS
["continue_with_firefox_accounts_button"])

def get_continue_with_firefox_button_locator(self) -> Locator:
return self._get_element_locator(self.__continue_with_firefox_accounts_button)
"""Get 'Continue with Firefox Accounts' button locator"""
return self._get_element_locator(self.AUTH_PAGE_CONTENT_LOCATORS
["continue_with_firefox_accounts_button"])

0 comments on commit 364e39f

Please sign in to comment.