Skip to content

Commit 0bf060c

Browse files
authored
Merge pull request #480 from mozilla/Hani/address_autofill_addresses_fields
Hani/ Test demo ad autofill address fields
2 parents 5f8479e + 49a8a09 commit 0bf060c

File tree

3 files changed

+76
-3
lines changed

3 files changed

+76
-3
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 "2888563"
12+
13+
14+
def test_demo_ad_autofill_address_fields(driver: Firefox, region: str, address_autofill: AddressFill, util: Utilities,
15+
autofill_popup: AutofillPopup):
16+
"""
17+
C2888563 - Verify Autofill functionality when selecting an entry from the dropdown for address fields
18+
"""
19+
# Create fake data and fill it in
20+
address_autofill.open()
21+
address_autofill_data = util.fake_autofill_data(region)
22+
address_autofill.save_information_basic(address_autofill_data)
23+
24+
# Click the "Save" button
25+
autofill_popup.click_doorhanger_button("save")
26+
27+
# List of field labels to be autofilled and verified
28+
fields_to_test = [
29+
"street-address",
30+
"address-level2",
31+
"address-level1", # This will be skipped for DE/FR
32+
"postal-code",
33+
"country"
34+
]
35+
36+
# Loop through each field and perform the autofill test
37+
for field in fields_to_test:
38+
address_autofill.autofill_and_verify(autofill_popup, field,
39+
address_autofill_data, util)
40+

l10n_CM/region/Unified.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
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_autofill_address_fields.py"
1618
"test_demo_ad_yellow_highlight_name_org.py",
1719
"test_demo_ad_yellow_highlight_address.py",
1820
"test_demo_ad_yellow_highlight_phone_email.py"
19-
2021
]
2122
}

modules/page_object_autofill.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ def verify_autofill_data(
515515
"ZIP Code": autofill_data.postal_code,
516516
"Country": autofill_data.country,
517517
"Email": autofill_data.email,
518-
"Phone": util.normalize_phone_number(autofill_data.telephone),
518+
"Phone": util.normalize_regional_phone_numbers(autofill_data.telephone, region),
519519
}
520520

521521
# Validate each field
@@ -528,7 +528,7 @@ def verify_autofill_data(
528528

529529
# Normalize phone numbers before comparison
530530
if field == "Phone":
531-
actual = util.normalize_phone_number(actual)
531+
actual = util.normalize_regional_phone_numbers(actual, region)
532532

533533
assert actual == expected, (
534534
f"Mismatch in {field}: Expected '{expected}', but got '{actual}'"
@@ -549,6 +549,38 @@ def verify_field_yellow_highlights(
549549
expected_highlighted_fields=expected_highlighted_fields,
550550
)
551551

552+
def autofill_and_verify(self, address_autofill_popup, field_label, address_autofill_data, util):
553+
"""
554+
Autofills a form field, verifies the data, and clears it if necessary.
555+
Parameters:
556+
----------
557+
address_autofill : AddressFill
558+
The address autofill handler.
559+
address_autofill_popup : AutofillPopup
560+
The popup handler for autofill suggestions.
561+
field_label : str
562+
The label of the field being autofilled.
563+
address_autofill_data : dict
564+
The generated autofill data for verification.
565+
region : str
566+
The region code to handle localization.
567+
"""
568+
# Skip address-level1 (State) selection for DE and FR
569+
if field_label == "address-level1" and address_autofill_data.country in ["DE", "FR"]:
570+
return
571+
572+
# Double-click a field and choose the first element from the autocomplete dropdown
573+
self.double_click("form-field", labels=[field_label])
574+
first_item = address_autofill_popup.get_nth_element(1)
575+
address_autofill_popup.click_on(first_item)
576+
577+
# Verify autofill data
578+
self.verify_autofill_data(address_autofill_data, address_autofill_data.country, util)
579+
580+
# Clear form autofill
581+
self.double_click("form-field", labels=[field_label])
582+
address_autofill_popup.click_clear_form_option()
583+
552584

553585
class TextAreaFormAutofill(Autofill):
554586
"""

0 commit comments

Comments
 (0)