diff --git a/modules/browser_object_autofill_popup.py b/modules/browser_object_autofill_popup.py index b9350d717..b0bbe5380 100644 --- a/modules/browser_object_autofill_popup.py +++ b/modules/browser_object_autofill_popup.py @@ -1,3 +1,4 @@ +import time from typing import Union from selenium.webdriver.remote.webelement import WebElement @@ -126,3 +127,19 @@ def get_primary_value(self, element: WebElement) -> str: Returns: str: The primary value extracted from the element's attribute """ return element.get_attribute("ac-value") + + @BasePage.context_chrome + def verify_update_password_doorhanger(self, nav, expected_text): + """ + Wait for and verify that the 'Update password' doorhanger is displayed + with the expected text + """ + # Wait for and open the doorhanger + time.sleep(1) + nav.expect(lambda _: nav.element_visible("password-notification-key")) + nav.click_on("password-notification-key") + + # Verify the doorhanger text + self.expect( + lambda _: expected_text in self.get_element("password-update-doorhanger").text + ) diff --git a/modules/page_object_autofill.py b/modules/page_object_autofill.py index bb198ac54..3c0b88f37 100644 --- a/modules/page_object_autofill.py +++ b/modules/page_object_autofill.py @@ -843,6 +843,28 @@ def verify_field_empty(self, field: str): self.parent.wait.until(lambda _: element.get_attribute("value") == "") return element + def generate_secure_password(self, context_menu): + """ + Opens the login autofill page, triggers the 'Suggest Strong Password' + option from the context menu, confirms the generated password, + and waits until the field is filled. + """ + self.parent.open() + self.parent.context_click("password-login-field") + context_menu.click_and_hide_menu("context-menu-suggest-strong-password") + + # Switch to chrome context to click 'Use a Securely Generated Password' + with self.parent.driver.context(self.parent.driver.CONTEXT_CHROME): + self.parent.get_element("generated-securely-password").click() + + # Wait until the password field is actually filled + self.parent.expect( + lambda _: ( + (elem := self.parent.get_element("password-login-field")) + and elem.get_attribute("value") not in ("", None) + ) + ) + class TextAreaFormAutofill(Autofill): """ diff --git a/tests/password_manager/test_auto_saved_generated_password_context_menu.py b/tests/password_manager/test_auto_saved_generated_password_context_menu.py index 6649a0dcd..78bfecdc8 100644 --- a/tests/password_manager/test_auto_saved_generated_password_context_menu.py +++ b/tests/password_manager/test_auto_saved_generated_password_context_menu.py @@ -19,7 +19,6 @@ def add_to_prefs_list(): return [("signon.rememberSignons", True)] -@pytest.mark.unstable(reason="Bug 1996838") def test_auto_saved_generated_password_context_menu(driver: Firefox): """ 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): autofill_popup_panel = AutofillPopup(driver) # Open login autofill test page and select "Suggest Strong Password..." from password field context menu - login_autofill.open() - login_autofill.context_click("password-login-field") - context_menu.click_and_hide_menu("context-menu-suggest-strong-password") - - # Select "Use a Securely Generated Password" in password field and check the "Update password" doorhanger - with driver.context(driver.CONTEXT_CHROME): - login_autofill.get_element("generated-securely-password").click() - - # Wait for password field to actually get filled - login_autofill.expect( - lambda _: login_autofill.get_element("password-login-field").get_attribute( - "value" - ) - != "" - ) + login_autofill.LoginForm(login_autofill).generate_secure_password(context_menu) # Verify the update doorhanger is displayed - nav.expect(lambda _: nav.element_visible("password-notification-key")) - nav.click_on("password-notification-key") - autofill_popup_panel.expect( - lambda _: UPDATE_DOORHANGER_TEXT - in autofill_popup_panel.get_element("password-update-doorhanger").text + autofill_popup_panel.verify_update_password_doorhanger( + nav, UPDATE_DOORHANGER_TEXT ) # Navigate to about:logins page