Skip to content

Commit 23a7835

Browse files
sv-hyacoubHani Yacoub
andauthored
Hani/ Stabilize test auto_saved_generated_password_context_menu (#883)
* Stabilize test auto_saved_generated_password_context_menu * add lower * remove lower * add sleep --------- Co-authored-by: Hani Yacoub <[email protected]>
1 parent ef873c3 commit 23a7835

File tree

3 files changed

+42
-21
lines changed

3 files changed

+42
-21
lines changed

modules/browser_object_autofill_popup.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import time
12
from typing import Union
23

34
from selenium.webdriver.remote.webelement import WebElement
@@ -126,3 +127,19 @@ def get_primary_value(self, element: WebElement) -> str:
126127
Returns: str: The primary value extracted from the element's attribute
127128
"""
128129
return element.get_attribute("ac-value")
130+
131+
@BasePage.context_chrome
132+
def verify_update_password_doorhanger(self, nav, expected_text):
133+
"""
134+
Wait for and verify that the 'Update password' doorhanger is displayed
135+
with the expected text
136+
"""
137+
# Wait for and open the doorhanger
138+
time.sleep(1)
139+
nav.expect(lambda _: nav.element_visible("password-notification-key"))
140+
nav.click_on("password-notification-key")
141+
142+
# Verify the doorhanger text
143+
self.expect(
144+
lambda _: expected_text in self.get_element("password-update-doorhanger").text
145+
)

modules/page_object_autofill.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,28 @@ def verify_field_empty(self, field: str):
843843
self.parent.wait.until(lambda _: element.get_attribute("value") == "")
844844
return element
845845

846+
def generate_secure_password(self, context_menu):
847+
"""
848+
Opens the login autofill page, triggers the 'Suggest Strong Password'
849+
option from the context menu, confirms the generated password,
850+
and waits until the field is filled.
851+
"""
852+
self.parent.open()
853+
self.parent.context_click("password-login-field")
854+
context_menu.click_and_hide_menu("context-menu-suggest-strong-password")
855+
856+
# Switch to chrome context to click 'Use a Securely Generated Password'
857+
with self.parent.driver.context(self.parent.driver.CONTEXT_CHROME):
858+
self.parent.get_element("generated-securely-password").click()
859+
860+
# Wait until the password field is actually filled
861+
self.parent.expect(
862+
lambda _: (
863+
(elem := self.parent.get_element("password-login-field"))
864+
and elem.get_attribute("value") not in ("", None)
865+
)
866+
)
867+
846868

847869
class TextAreaFormAutofill(Autofill):
848870
"""

tests/password_manager/test_auto_saved_generated_password_context_menu.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ def add_to_prefs_list():
1919
return [("signon.rememberSignons", True)]
2020

2121

22-
@pytest.mark.unstable(reason="Bug 1996838")
2322
def test_auto_saved_generated_password_context_menu(driver: Firefox):
2423
"""
2524
C2248176 - Securely Generated Password is auto-saved when generated from password field context menu
@@ -34,28 +33,11 @@ def test_auto_saved_generated_password_context_menu(driver: Firefox):
3433
autofill_popup_panel = AutofillPopup(driver)
3534

3635
# Open login autofill test page and select "Suggest Strong Password..." from password field context menu
37-
login_autofill.open()
38-
login_autofill.context_click("password-login-field")
39-
context_menu.click_and_hide_menu("context-menu-suggest-strong-password")
40-
41-
# Select "Use a Securely Generated Password" in password field and check the "Update password" doorhanger
42-
with driver.context(driver.CONTEXT_CHROME):
43-
login_autofill.get_element("generated-securely-password").click()
44-
45-
# Wait for password field to actually get filled
46-
login_autofill.expect(
47-
lambda _: login_autofill.get_element("password-login-field").get_attribute(
48-
"value"
49-
)
50-
!= ""
51-
)
36+
login_autofill.LoginForm(login_autofill).generate_secure_password(context_menu)
5237

5338
# Verify the update doorhanger is displayed
54-
nav.expect(lambda _: nav.element_visible("password-notification-key"))
55-
nav.click_on("password-notification-key")
56-
autofill_popup_panel.expect(
57-
lambda _: UPDATE_DOORHANGER_TEXT
58-
in autofill_popup_panel.get_element("password-update-doorhanger").text
39+
autofill_popup_panel.verify_update_password_doorhanger(
40+
nav, UPDATE_DOORHANGER_TEXT
5941
)
6042

6143
# Navigate to about:logins page

0 commit comments

Comments
 (0)