Skip to content

Commit 16d4c98

Browse files
authored
Merge pull request #577 from mozilla/Hani/refactor_pass_manager_batch2
Hani/refactor password manager batch2
2 parents 7402174 + 4ae3130 commit 16d4c98

18 files changed

+162
-111
lines changed

tests/password_manager/test_about_logins_navigation_from_context_menu.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
from modules.page_object import LoginAutofill
66

77

8+
ABOUT_LOGINS_PAGE_TITLE = "Passwords"
9+
10+
811
@pytest.fixture()
912
def test_case():
1013
return "2241087"
@@ -19,13 +22,13 @@ def test_about_logins_navigation_from_login_form_context_menu(driver: Firefox):
1922
# Instantiate objects
2023
context_menu = ContextMenu(driver)
2124
tabs = TabBar(driver)
22-
login = LoginAutofill(driver).open()
25+
login = LoginAutofill(driver)
2326

2427
# Access the manage passwords in context menu from the username field in the demo login form
25-
username_field = login.get_element("username-field")
26-
login.context_click(username_field)
28+
login.open()
29+
login.context_click("username-field")
2730
context_menu.click_and_hide_menu("context-menu-manage-passwords")
2831

2932
# Verify that the about:logins page is opened in a new tab
3033
tabs.wait_for_num_tabs(2)
31-
tabs.title_contains("Passwords")
34+
tabs.title_contains(ABOUT_LOGINS_PAGE_TITLE)

tests/password_manager/test_about_logins_navigation_from_hamburger_menu.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import pytest
22
from selenium.webdriver import Firefox
3-
43
from modules.browser_object import PanelUi, TabBar
54

65

6+
ABOUT_LOGINS_PAGE_TITLE = "Passwords"
7+
8+
79
@pytest.fixture()
810
def test_case():
911
return "2241082"
@@ -23,4 +25,4 @@ def test_about_logins_navigation_from_password_hamburger_menu(driver: Firefox):
2325

2426
# Verify that the about:logins page is opened in a new tab
2527
tabs.wait_for_num_tabs(2)
26-
tabs.title_contains("Passwords")
28+
tabs.title_contains(ABOUT_LOGINS_PAGE_TITLE)

tests/password_manager/test_add_password_non_ascii_chars.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
from modules.page_object import AboutLogins
55

66

7+
WEBSITE_ADDRESS = "mozilla.org"
8+
USERNAME = "£$µ→“"
9+
PASSWORD = "£$µ→“"
10+
11+
712
@pytest.fixture()
813
def test_case():
914
return "2241113"
@@ -23,16 +28,15 @@ def test_add_password_non_ascii_chars(driver: Firefox):
2328
# Complete all the fields with valid data and click the "Save" button.
2429
about_logins.create_new_login(
2530
{
26-
"origin": "mozilla.org",
27-
"username": "£$µ→“",
28-
"password": "£$µ→“",
31+
"origin": WEBSITE_ADDRESS,
32+
"username": USERNAME,
33+
"password": PASSWORD,
2934
}
3035
)
3136

3237
# Check password added in the listbox
33-
about_logins.get_element("login-list-item")
3438
logins = about_logins.get_elements("login-list-item")
3539
mozilla_login = next(
36-
login for login in logins if login.get_attribute("title") == "mozilla.org"
40+
login for login in logins if login.get_attribute("title") == WEBSITE_ADDRESS
3741
)
3842
assert mozilla_login

tests/password_manager/test_add_password_save_valid_data.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
from modules.page_object import AboutLogins
66

77

8+
WEBSITE_ADDRESS = "mozilla.org"
9+
USERNAME = "username"
10+
PASSWORD = "password"
11+
12+
813
@pytest.fixture()
914
def test_case():
1015
return "2241112"
@@ -24,17 +29,16 @@ def test_add_password_save_valid_data(driver: Firefox):
2429
# Complete all the fields with valid data and click the "Save" button.
2530
about_logins.create_new_login(
2631
{
27-
"origin": "mozilla.org",
28-
"username": "username",
29-
"password": "password",
32+
"origin": WEBSITE_ADDRESS,
33+
"username": USERNAME,
34+
"password": PASSWORD,
3035
}
3136
)
3237

3338
# Check password added in the listbox
34-
about_logins.get_element("login-list-item")
3539
logins = about_logins.get_elements("login-list-item")
3640
mozilla_login = next(
37-
login for login in logins if login.get_attribute("title") == "mozilla.org"
41+
login for login in logins if login.get_attribute("title") == WEBSITE_ADDRESS
3842
)
3943
assert mozilla_login
4044

tests/password_manager/test_add_primary_password.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
from modules.util import BrowserActions
66

77

8+
PRIMARY_PASSWORD = "securePassword1"
9+
ALERT_MESSAGE = "Primary Password successfully changed."
10+
11+
812
@pytest.fixture()
913
def test_case():
1014
return "2245178"
@@ -15,9 +19,6 @@ def hard_quit():
1519
return True
1620

1721

18-
PRIMARY_PASSWORD = "securePassword1"
19-
20-
2122
def test_add_primary_password(driver: Firefox):
2223
"""
2324
C2245178: Verify that a primary password can be added in about:preferences#privacy
@@ -45,5 +46,5 @@ def test_add_primary_password(driver: Firefox):
4546
# Check that the pop-up appears
4647
with driver.context(driver.CONTEXT_CHROME):
4748
alert = about_prefs.get_alert()
48-
assert alert.text == "Primary Password successfully changed."
49+
assert alert.text == ALERT_MESSAGE
4950
alert.accept()

tests/password_manager/test_auto_saved_generated_password_context_menu.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import pytest
22
from selenium.webdriver import Firefox
3-
43
from modules.browser_object import AutofillPopup, ContextMenu, Navigation, TabBar
54
from modules.page_object import AboutLogins, LoginAutofill
65

76

7+
UPDATE_DOORHANGER_TEXT = "Update password for mozilla.github.io?"
8+
TEST_WEBSITE = "https://mozilla.github.io/"
9+
10+
811
@pytest.fixture()
912
def test_case():
1013
return "2248176"
@@ -30,28 +33,26 @@ def test_auto_saved_generated_password_context_menu(driver: Firefox):
3033

3134
# Open login autofill test page and select "Suggest Strong Password..." from password field context menu
3235
login_autofill.open()
33-
password_field = login_autofill.get_element("password-login-field")
34-
login_autofill.context_click(password_field)
36+
login_autofill.context_click("password-login-field")
3537
context_menu.click_and_hide_menu("context-menu-suggest-strong-password")
3638

3739
# Select "Use a Securely Generated Password" in password field and check the "Update password" doorhanger
3840
# is displayed
3941
with driver.context(driver.CONTEXT_CHROME):
4042
login_autofill.get_element("generated-securely-password").click()
41-
nav.element_visible("password-notification-key")
4243
nav.click_on("password-notification-key")
4344
update_doorhanger = autofill_popup_panel.get_element(
4445
"password-update-doorhanger"
4546
)
46-
assert update_doorhanger.text == "Update password for mozilla.github.io?"
47+
assert update_doorhanger.text == UPDATE_DOORHANGER_TEXT
4748

4849
# Navigate to about:logins page
4950
tabs.switch_to_new_tab()
5051
about_logins.open()
5152

5253
# Verify the website address saves the correct value
5354
about_logins.expect_element_attribute_contains(
54-
"website-address", "href", "https://mozilla.github.io/"
55+
"website-address", "href", TEST_WEBSITE
5556
)
5657

5758
# Verify the username field has no value

tests/password_manager/test_autocomplete_dropdown_is_toggled_for_focused_login_fields_on_page_load.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
from modules.page_object_generics import GenericPage
88

99

10+
BSKY_URL = "https://bsky.app/"
11+
USERNAME = "username1"
12+
PASSWORD = "password1"
13+
USERNAME2 = "username2"
14+
PASSWORD2 = "password2"
15+
16+
1017
@pytest.fixture()
1118
def test_case():
1219
return "2240907"
@@ -18,9 +25,6 @@ def add_to_prefs_list():
1825
return [("signon.rememberSignons", True)]
1926

2027

21-
BSKY_URL = "https://bsky.app/"
22-
23-
2428
def test_autocomplete_dropdown_is_toggled_for_focused_login_fields_on_page_load(
2529
driver: Firefox,
2630
):
@@ -43,17 +47,17 @@ def test_autocomplete_dropdown_is_toggled_for_focused_login_fields_on_page_load(
4347
about_logins.click_add_login_button()
4448
about_logins.create_new_login(
4549
{
46-
"origin": "https://bsky.app/",
47-
"username": "username1",
48-
"password": "password1",
50+
"origin": BSKY_URL,
51+
"username": USERNAME,
52+
"password": PASSWORD,
4953
}
5054
)
5155
about_logins.click_add_login_button()
5256
about_logins.create_new_login(
5357
{
54-
"origin": "https://bsky.app/",
55-
"username": "username2",
56-
"password": "password2",
58+
"origin": BSKY_URL,
59+
"username": USERNAME2,
60+
"password": PASSWORD2,
5761
}
5862
)
5963

@@ -63,4 +67,4 @@ def test_autocomplete_dropdown_is_toggled_for_focused_login_fields_on_page_load(
6367
generic_page.get_element("bsky-signin-button").click()
6468
with driver.context(driver.CONTEXT_CHROME):
6569
username_element = login_autofill.get_element("bsky-credentials")
66-
assert username_element.get_attribute("ac-value") == "username1"
70+
assert username_element.get_attribute("ac-value") == USERNAME

tests/password_manager/test_can_view_password_when_PP_enabled.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
from modules.util import BrowserActions
88

99

10+
URL_TO_TEST = "https://mozilla.github.io/"
11+
USERNAME = "username"
12+
PASSWORD = "password"
13+
PRIMARY_PASSWORD = "securePassword1"
14+
15+
1016
@pytest.fixture()
1117
def test_case():
1218
return "2264688"
@@ -16,7 +22,7 @@ def test_password_can_be_shown(driver: Firefox):
1622
"""
1723
C2264688: Verify that the Show Password button prompts for the Primary Password before revealing the saved login
1824
"""
19-
# instantiate object
25+
# Instantiate object
2026
about_logins = AboutLogins(driver)
2127
about_prefs = AboutPrefs(driver, category="privacy")
2228
ba = BrowserActions(driver)
@@ -28,9 +34,9 @@ def test_password_can_be_shown(driver: Firefox):
2834
# Complete all the fields with valid data and click the "Save" button.
2935
about_logins.create_new_login(
3036
{
31-
"origin": "mozilla.org",
32-
"username": "username",
33-
"password": "password",
37+
"origin": URL_TO_TEST,
38+
"username": USERNAME,
39+
"password": PASSWORD,
3440
}
3541
)
3642

@@ -46,8 +52,8 @@ def test_password_can_be_shown(driver: Firefox):
4652
)
4753

4854
# Primary password can be changed
49-
about_prefs.get_element("enter-new-password").send_keys("securePassword1")
50-
about_prefs.get_element("reenter-new-password").send_keys("securePassword1")
55+
about_prefs.get_element("enter-new-password").send_keys(PRIMARY_PASSWORD)
56+
about_prefs.get_element("reenter-new-password").send_keys(PRIMARY_PASSWORD)
5157
about_prefs.click_on("submit-password")
5258

5359
# Check that the pop-up appears
@@ -56,8 +62,7 @@ def test_password_can_be_shown(driver: Firefox):
5662
alert.accept()
5763

5864
about_logins.open()
59-
show_password_button = about_logins.get_element("show-password-checkbox")
60-
show_password_button.click()
65+
about_logins.click_on("show-password-checkbox")
6166

6267
with driver.context(driver.CONTEXT_CHROME):
6368
driver.switch_to.window(driver.window_handles[-1])
@@ -68,7 +73,7 @@ def test_password_can_be_shown(driver: Firefox):
6873
primary_password_input_field = about_logins.get_element(
6974
"primary-password-dialog-input-field"
7075
)
71-
primary_password_input_field.send_keys("securePassword1")
76+
primary_password_input_field.send_keys(PRIMARY_PASSWORD)
7277
primary_password_input_field.send_keys(Keys.ENTER)
7378

7479
# Verify that the password is unmasked by checking that the type is now text.
Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import pytest
22
from selenium.webdriver import Firefox
3-
43
from modules.page_object_about_pages import AboutLogins
54

65

6+
URL_TO_TEST = "https://mozilla.github.io/"
7+
USERNAME = "username"
8+
PASSWORD = "password"
9+
NEW_USERNAME = "Testuser"
10+
ADD_TO_PASSWORD = "123"
11+
NEW_PASSWORD = "password123"
12+
13+
714
@pytest.fixture()
815
def test_case():
916
return "2241121"
@@ -13,38 +20,38 @@ def test_changes_made_in_edit_mode_are_saved(driver: Firefox):
1320
"""
1421
C2241121 - Verify that changes made in Edit Mode are saved
1522
"""
16-
# instantiate object
23+
# Instantiate object
1724
about_logins = AboutLogins(driver)
1825

1926
# Open about:logins and add a new login
2027
about_logins.open()
2128
about_logins.click_add_login_button()
2229
about_logins.create_new_login(
2330
{
24-
"origin": "https://mozilla.github.io/",
25-
"username": "username",
26-
"password": "password",
31+
"origin": URL_TO_TEST,
32+
"username": USERNAME,
33+
"password": PASSWORD,
2734
}
2835
)
2936
# Click the "Edit" button
3037
about_logins.click_on("edit-login")
3138

3239
# Change username and the password
33-
about_logins.get_element("about-logins-page-username-field").send_keys("Testuser")
34-
about_logins.get_element("about-logins-page-password-hidden").send_keys("123")
40+
about_logins.get_element("about-logins-page-username-field").send_keys(NEW_USERNAME)
41+
about_logins.get_element("about-logins-page-password-hidden").send_keys(ADD_TO_PASSWORD)
3542

3643
# Click the "Save" button
3744
about_logins.click_on("save-edited-login")
3845

3946
# Verify the username field is changed
4047
about_logins.expect_element_attribute_contains(
41-
"about-logins-page-username-field", "value", "Testuser"
48+
"about-logins-page-username-field", "value", NEW_USERNAME
4249
)
4350

4451
# Click the "Show Password" button
4552
about_logins.click_on("show-password-checkbox")
4653

4754
# Verify the newly entered password is correctly displayed
4855
about_logins.expect_element_attribute_contains(
49-
"about-logins-page-password-revealed", "value", "password123"
56+
"about-logins-page-password-revealed", "value", NEW_PASSWORD
5057
)

0 commit comments

Comments
 (0)