Skip to content

Commit 342938d

Browse files
authored
Merge pull request #497 from mozilla/as/dropdown-presence-addresses
Anca/ l10n demo - Addresses fields autofill dropdown activation
2 parents 95691cd + e60110f commit 342938d

File tree

4 files changed

+100
-14
lines changed

4 files changed

+100
-14
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import pytest
2+
from selenium.webdriver import Firefox
3+
4+
from modules.browser_object_autofill_popup import AutofillPopup
5+
from modules.page_object_autofill import AddressFill
6+
from modules.util import Utilities
7+
8+
9+
@pytest.fixture()
10+
def test_case():
11+
return "2888561"
12+
13+
14+
def test_dropdown_presence_address_field(
15+
driver: Firefox,
16+
region: str,
17+
address_autofill: AddressFill,
18+
util: Utilities,
19+
autofill_popup: AutofillPopup,
20+
):
21+
"""
22+
C2888561 - Verify that the autofill dropdown is displayed for the eligible address fields after an address was
23+
previously saved
24+
"""
25+
26+
# Create fake data and fill it in
27+
address_autofill.open()
28+
address_autofill_data = util.fake_autofill_data(region)
29+
address_autofill.save_information_basic(address_autofill_data)
30+
31+
# Click the "Save" button
32+
autofill_popup.click_doorhanger_button("save")
33+
34+
fields_to_test = [
35+
"street-address",
36+
"address-level2",
37+
"address-level1",
38+
"postal-code",
39+
"country",
40+
]
41+
42+
address_autofill.verify_autofill_dropdown_addresses(
43+
autofill_popup=autofill_popup, fields_to_test=fields_to_test, region=region
44+
)

l10n_CM/Unified/test_demo_cc_dropdown_presence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ def test_dropdown_presence_credit_card(
3636
credit_card_fill_obj.open()
3737

3838
# Verify autofill dropdown is displayed only for the eligible fields
39-
credit_card_fill_obj.verify_autofill_dropdown_all_fields(autofill_popup)
39+
credit_card_fill_obj.verify_autofill_dropdown_credit_card(autofill_popup)

l10n_CM/region/Unified.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@
1313
"test_demo_cc_doorhanger_shown_on_valid_credit_card_submission.py",
1414
"test_demo_cc_dropdown_presence.py",
1515
"test_demo_cc_yellow_highlight.py",
16-
"test_demo_ad_yellow_highlight.py",
17-
"test_demo_ad_yellow_highlight_phone_email.py",
18-
"test_demo_ad_yellow_highlight.py",
19-
"test_demo_ad_autofill_address_fields.py",
16+
"test_demo_ad_autofill_address_fields.py"
2017
"test_demo_ad_yellow_highlight_name_org.py",
2118
"test_demo_ad_yellow_highlight_address.py",
22-
"test_demo_ad_clear_name_org.py",
2319
"test_demo_ad_yellow_highlight_phone_email.py",
20+
"test_demo_ad_dropdown_presence_address.py
2421
"test_demo_ad_clear_name_org.py",
2522
"test_demo_ad_clear_address_fields.py",
2623
"test_demo_ad_clear_tel_email.py"

modules/page_object_autofill.py

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,43 @@ def click_form_button(self, field_name):
3939
"""Clicks submit on the form"""
4040
self.click_on("submit-button", labels=[field_name])
4141

42+
def verify_field_autofill_dropdown(
43+
self,
44+
autofill_popup: AutofillPopup,
45+
fields_to_test: List[str],
46+
excluded_fields: Optional[List[str]] = None,
47+
region: Optional[str] = None,
48+
):
49+
"""
50+
A common method to check which fields trigger the autofill dropdown. This is used in both CC and Address pages.
51+
- fields_to_test: The primary list of fields for this page (cc fields, address fields).
52+
- excluded_fields: Fields that should NOT trigger an autofill dropdown.
53+
- region: If provided, handle region-specific behavior (e.g., skip address-level1 for DE/FR).
54+
"""
55+
# Create a copy of fields_to_test to avoid modifying the original
56+
fields_to_check = fields_to_test[:]
57+
58+
# Handle region-specific behavior
59+
if region in ["DE", "FR"] and "address-level1" in fields_to_check:
60+
fields_to_check.remove("address-level1")
61+
62+
# Check fields that SHOULD trigger the autofill dropdown
63+
for field_name in fields_to_check:
64+
self.double_click("form-field", labels=[field_name])
65+
autofill_popup.ensure_autofill_dropdown_visible()
66+
logging.info(f"Autofill dropdown appears for field '{field_name}'.")
67+
68+
# Check fields that should NOT trigger the autofill dropdown
69+
if excluded_fields:
70+
for field_name in excluded_fields:
71+
self.double_click("form-field", labels=[field_name])
72+
autofill_popup.ensure_autofill_dropdown_not_visible()
73+
logging.info(
74+
f"No autofill dropdown appears for field '{field_name}', as expected."
75+
)
76+
77+
return self
78+
4279
def verify_field_highlight(
4380
self,
4481
fields_to_test: List[str],
@@ -136,14 +173,11 @@ def fill_credit_card_info(self, info: CreditCardBase):
136173

137174
self.click_form_button("submit")
138175

139-
def verify_autofill_dropdown_all_fields(self, ccp: AutofillPopup):
140-
"""Given a CreditCardPopup object, verify all fields"""
141-
for field in self.fields:
142-
self.double_click("form-field", labels=[field])
143-
ccp.ensure_autofill_dropdown_visible()
144-
# Ensure 'cc-csc' does NOT trigger the autofill dropdown
145-
self.double_click("form-field", labels=["cc-csc"])
146-
ccp.ensure_autofill_dropdown_not_visible()
176+
def verify_autofill_dropdown_credit_card(self, autofill_popup: AutofillPopup):
177+
"""Verifies autofill dropdown for credit card fields."""
178+
return self.verify_field_autofill_dropdown(
179+
autofill_popup, fields_to_test=self.fields, excluded_fields=["cc-csc"]
180+
)
147181

148182
def verify_credit_card_form_data(
149183
self, credit_card_sample_data: CreditCardBase
@@ -551,6 +585,17 @@ def verify_field_yellow_highlights(
551585
expected_highlighted_fields=expected_highlighted_fields,
552586
)
553587

588+
def verify_autofill_dropdown_addresses(
589+
self, autofill_popup: AutofillPopup, region=None, fields_to_test=None
590+
):
591+
"""Verifies autofill dropdown for address fields."""
592+
if fields_to_test is None:
593+
fields_to_test = self.fields
594+
595+
return self.verify_field_autofill_dropdown(
596+
autofill_popup=autofill_popup, fields_to_test=fields_to_test, region=region
597+
)
598+
554599
def autofill_and_verify(
555600
self, address_autofill_popup, field_label, address_autofill_data, util
556601
):

0 commit comments

Comments
 (0)