Skip to content

Commit 5034ca4

Browse files
sv-hyacoubHani Yacoub
andauthored
Hani/ Refactor Password Manager (#815)
* Refactor * Skip failing test * Edit bug number --------- Co-authored-by: Hani Yacoub <[email protected]>
1 parent 575e758 commit 5034ca4

11 files changed

+60
-47
lines changed

modules/page_object_about_pages.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ def remove_password_csv(self, downloads_dir):
193193
if delete_files_regex.match(file):
194194
os.remove(passwords_csv)
195195

196+
def verify_csv_export(self, downloads_folder: str, filename: str):
197+
"""Wait until the exported CSV file is present in the target folder."""
198+
csv_file = os.path.join(downloads_folder, filename)
199+
self.wait.until(lambda _: os.path.exists(csv_file))
200+
return csv_file
201+
196202

197203
class AboutPrivatebrowsing(BasePage):
198204
"""

modules/page_object_autofill.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,30 @@ def submit(self) -> None:
807807
self.submit_button = self.parent.get_element("submit-button-login")
808808
self.submit_button.click()
809809

810+
def verify_password_value(self, expected_password: str, field: str = "password-login-field"):
811+
"""Wait until the password field contains the expected value."""
812+
element = self.parent.get_element(field)
813+
self.parent.wait.until(lambda _: element.get_attribute("value") == expected_password)
814+
return element
815+
816+
def verify_username_value(self, expected_username: str, field: str = "username-login-field"):
817+
"""Wait until the username field contains the expected value."""
818+
element = self.parent.get_element(field)
819+
self.parent.wait.until(lambda _: element.get_attribute("value") == expected_username)
820+
return element
821+
822+
def verify_password_length(self, expected_length: int = 8, field: str = "password-login-field"):
823+
"""Wait until the password field contains the expected number of characters."""
824+
element = self.parent.get_element(field)
825+
self.parent.wait.until(lambda _: len(element.get_attribute("value")) == expected_length)
826+
return element
827+
828+
def verify_field_empty(self, field: str):
829+
"""Wait until the given field is empty."""
830+
element = self.parent.get_element(field)
831+
self.parent.wait.until(lambda _: element.get_attribute("value") == "")
832+
return element
833+
810834

811835
class TextAreaFormAutofill(Autofill):
812836
"""

tests/password_manager/test_add_primary_password.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def test_add_primary_password(driver: Firefox):
4343
about_prefs.click_on("submit-password")
4444

4545
# Check that the pop-up appears
46-
with driver.context(driver.CONTEXT_CHROME):
47-
alert = about_prefs.get_alert()
48-
assert alert.text == ALERT_MESSAGE
49-
alert.accept()
46+
alert = about_prefs.get_alert()
47+
assert alert.text == ALERT_MESSAGE
48+
alert.accept()

tests/password_manager/test_auto_saved_generated_password_context_menu.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ def test_auto_saved_generated_password_context_menu(driver: Firefox):
5252
)
5353

5454
# Verify the update doorhanger is displayed
55-
with driver.context(driver.CONTEXT_CHROME):
56-
sleep(3)
57-
nav.click_on("password-notification-key")
58-
autofill_popup_panel.expect(
59-
lambda _: UPDATE_DOORHANGER_TEXT
60-
in autofill_popup_panel.get_element("password-update-doorhanger").text
61-
)
55+
# with driver.context(driver.CONTEXT_CHROME):
56+
sleep(3)
57+
nav.click_on("password-notification-key")
58+
autofill_popup_panel.expect(
59+
lambda _: UPDATE_DOORHANGER_TEXT
60+
in autofill_popup_panel.get_element("password-update-doorhanger").text
61+
)
6262

6363
# Navigate to about:logins page
6464
tabs.switch_to_new_tab()

tests/password_manager/test_can_view_password_when_PP_enabled.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ def test_password_can_be_shown(driver: Firefox):
5656
about_prefs.click_on("submit-password")
5757

5858
# Check that the pop-up appears
59-
with driver.context(driver.CONTEXT_CHROME):
60-
alert = about_prefs.get_alert()
61-
alert.accept()
59+
# with driver.context(driver.CONTEXT_CHROME):
60+
alert = about_prefs.get_alert()
61+
alert.accept()
6262

6363
about_logins.open()
6464
about_logins.click_on("show-password-checkbox")

tests/password_manager/test_never_save_login_via_doorhanger.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ def test_never_save_login_via_doorhanger(driver: Firefox):
5353
login_autofill.open()
5454

5555
# Verify the username field is empty
56-
username_element = login_autofill.get_element("username-login-field")
57-
login_autofill.wait.until(lambda _: username_element.get_attribute("value") == "")
56+
username_element = login_form.verify_field_empty("username-login-field")
57+
assert username_element.get_attribute("value") == ""
5858

5959
# Verify the password field is empty
60-
password_element = login_autofill.get_element("password-login-field")
61-
login_autofill.wait.until(lambda _: password_element.get_attribute("value") == "")
60+
password_element = login_form.verify_field_empty("password-login-field")
61+
assert password_element.get_attribute("value") == ""
6262

6363
# Navigate to about:preferences#privacy and open Exceptions - Saved Passwords modal
6464
about_prefs.open()

tests/password_manager/test_password_csv_correctness.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def test_password_csv_correctness(
4242
page.navigate_dialog_to_location(downloads_folder, PASSWORDS_FILE)
4343

4444
# Verify the exported csv file is present in the target folder
45-
csv_file = os.path.join(downloads_folder, PASSWORDS_FILE)
46-
about_logins.wait.until(lambda _: os.path.exists(csv_file))
45+
csv_file = about_logins.verify_csv_export(downloads_folder, "passwords.csv")
46+
assert os.path.exists(csv_file)
4747

4848
# Verify the contents of the exported csv file
4949
guid_pattern = re.compile(

tests/password_manager/test_password_csv_export.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def test_password_csv_export(
4444
keyboard.tap(Key.enter)
4545

4646
# Verify the exported csv file is present in the target folder
47-
csv_file = os.path.join(downloads_folder, PASSWORDS_FILE)
48-
about_logins.wait.until(lambda _: os.path.exists(csv_file))
47+
csv_file = about_logins.verify_csv_export(downloads_folder, "passwords.csv")
48+
assert os.path.exists(csv_file)
4949

5050
# Delete the password.csv created
5151
about_logins.remove_password_csv(downloads_folder)

tests/password_manager/test_save_login_via_doorhanger.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,11 @@ def test_save_login_via_doorhanger(driver: Firefox):
4747
# Verify the username field has the saved value
4848
login_autofill.open()
4949

50-
username_element = login_autofill.get_element("username-login-field")
51-
login_autofill.wait.until(
52-
lambda _: username_element.get_attribute("value") == USERNAME
53-
)
50+
login_form.verify_username_value(USERNAME)
5451

5552
# Select Reveal password from password field context menu for headed run purpose only
5653
login_autofill.context_click("password-login-field")
5754
context_menu.click_and_hide_menu("context-menu-reveal-password")
5855

5956
# Verify the password matches the password value
60-
password_element = login_autofill.get_element("password-login-field")
61-
login_autofill.wait.until(
62-
lambda _: password_element.get_attribute("value") == PASSWORD
63-
)
57+
login_form.verify_password_value(PASSWORD)

tests/password_manager/test_saved_hyperlink_redirects_to_corresponding_page.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,13 @@ def test_saved_hyperlink_redirects_to_corresponding_page(driver: Firefox):
4949
about_logins.switch_to_new_tab()
5050
about_logins.url_contains("mozilla.github")
5151

52-
# Verify that the saved login is recognized
52+
# Creating an instance of the LoginForm within the LoginAutofill page object
5353
login_autofill.open()
54+
login_form = LoginAutofill.LoginForm(login_autofill)
5455

5556
# Verify the username field has the saved value
56-
username_element = login_autofill.get_element("username-login-field")
57-
login_autofill.wait.until(
58-
lambda _: username_element.get_attribute("value") == USERNAME
59-
)
57+
login_form.verify_username_value(USERNAME)
6058

6159
# Verify the password field is filled with a value that match the length of the saved password
62-
password_element = login_autofill.get_element("password-login-field")
63-
login_autofill.wait.until(
64-
lambda _: len(password_element.get_attribute("value")) == 8
65-
)
60+
password_element = login_form.verify_password_length(8)
61+
assert len(password_element.get_attribute("value")) == 8

0 commit comments

Comments
 (0)