Skip to content

Commit fa3a439

Browse files
change faker and aboutpref to allow for better address autofill
1 parent 342938d commit fa3a439

12 files changed

+96
-88
lines changed

l10n_CM/Unified/test_demo_ad_clear_address_fields.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ def test_case():
1212

1313

1414
def test_demo_ad_clear_address_fields(
15-
driver: Firefox,
16-
region: str,
17-
address_autofill: AddressFill,
18-
util: Utilities,
19-
autofill_popup: AutofillPopup
15+
driver: Firefox,
16+
region: str,
17+
address_autofill: AddressFill,
18+
util: Utilities,
19+
autofill_popup: AutofillPopup,
2020
):
2121
"""
2222
C2888565 - Verify clear functionality after selecting an entry from address fields
@@ -35,7 +35,7 @@ def test_demo_ad_clear_address_fields(
3535
"address-level2",
3636
"address-level1", # This will be skipped for DE/FR
3737
"postal-code",
38-
"country"
38+
"country",
3939
]
4040

4141
# Loop through each field and perform the autofill test

l10n_CM/Unified/test_demo_ad_clear_name_org.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ def test_case():
1212

1313

1414
def test_demo_ad_clear_name_org(
15-
driver: Firefox,
16-
region: str,
17-
address_autofill: AddressFill,
18-
util: Utilities,
19-
autofill_popup: AutofillPopup
15+
driver: Firefox,
16+
region: str,
17+
address_autofill: AddressFill,
18+
util: Utilities,
19+
autofill_popup: AutofillPopup,
2020
):
2121
"""
2222
C2888560 - Verify clear functionality after selecting an entry from name/org fields
@@ -30,10 +30,7 @@ def test_demo_ad_clear_name_org(
3030
autofill_popup.click_doorhanger_button("save")
3131

3232
# List of field labels to be autofilled and verified
33-
fields_to_test = [
34-
"name",
35-
"organization"
36-
]
33+
fields_to_test = ["name", "organization"]
3734

3835
# Loop through each field and perform the autofill test
3936
for field in fields_to_test:

l10n_CM/Unified/test_demo_ad_clear_tel_email.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ def test_case():
1212

1313

1414
def test_demo_ad_clear_tel_email(
15-
driver: Firefox,
16-
region: str,
17-
address_autofill: AddressFill,
18-
util: Utilities,
19-
autofill_popup: AutofillPopup
15+
driver: Firefox,
16+
region: str,
17+
address_autofill: AddressFill,
18+
util: Utilities,
19+
autofill_popup: AutofillPopup,
2020
):
2121
"""
2222
C2888571 - Verify clear functionality after selecting an entry from tele/email fields
@@ -31,10 +31,7 @@ def test_demo_ad_clear_tel_email(
3131
autofill_popup.click_doorhanger_button("save")
3232

3333
# List of field labels to be autofilled and verified
34-
fields_to_test = [
35-
"email",
36-
"tel"
37-
]
34+
fields_to_test = ["email", "tel"]
3835

3936
# Loop through each field and perform the autofill test
4037
for field in fields_to_test:

l10n_CM/Unified/test_demo_ad_verify_new_address_added.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ def test_case():
1212
return "2886580"
1313

1414

15-
@pytest.fixture()
16-
def region():
17-
return "US"
18-
19-
2015
@pytest.fixture()
2116
def add_prefs(region: str):
2217
return [
@@ -39,22 +34,23 @@ def test_verify_new_address_is_added(
3934
# open saved addresses and add entry
4035
about_prefs_privacy.open()
4136
about_prefs_privacy.add_entry_to_saved_addresses(address_autofill_data)
37+
driver.switch_to.frame(1)
4238

4339
# verify that the address saved is the same.
4440
# The address saved in step 2 is listed in the "Saved addresses" modal: name and organization
4541
elements = about_prefs_privacy.get_element("saved-addresses-values").text.split(",")
4642
address_match = all(
47-
data_sanitizer(element, region, inverted_state_province_abbr)
43+
data_sanitizer(util, element, region, inverted_state_province_abbr)
4844
in address_autofill_data.__dict__.values()
4945
for element in elements
5046
)
5147
assert address_match, "Address found is not equal to address created!"
5248

5349

54-
def data_sanitizer(value: str, region: str, state_province: Dict):
50+
def data_sanitizer(util: Utilities, value: str, region: str, state_province: Dict):
5551
value = value.strip()
5652
if value[0] == "+":
57-
return value[1:]
53+
return util.normalize_phone_number(value)
5854
elif len(value) == 2 and value != region:
5955
return state_province.get(value, value)
6056
return value

l10n_CM/region/US.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
{
22
"region": "US",
3-
"tests": [
4-
"test_demo_ad_verify_new_address_added.py"
5-
]
3+
"tests": []
64
}

l10n_CM/region/Unified.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +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_autofill_address_fields.py"
16+
"test_demo_ad_autofill_address_fields.py",
1717
"test_demo_ad_yellow_highlight_name_org.py",
1818
"test_demo_ad_yellow_highlight_address.py",
1919
"test_demo_ad_yellow_highlight_phone_email.py",
20-
"test_demo_ad_dropdown_presence_address.py
20+
"test_demo_ad_dropdown_presence_address.py",
2121
"test_demo_ad_clear_name_org.py",
2222
"test_demo_ad_clear_address_fields.py",
2323
"test_demo_ad_clear_tel_email.py"

l10n_CM/run_l10n.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
valid_flags = {"--run-headless", "-n", "--reruns"}
99
flag_with_parameter = {"-n", "--reruns"}
1010
valid_region = {"US", "CA", "DE", "FR"}
11+
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
1112

1213

1314
def run_tests(reg, flg, all_tests):

modules/classes/autofill_base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class AutofillAddressBase:
1010
address_level_1: str | None = None
1111
postal_code: str | None = None
1212
country: str | None = None
13+
country_code: str | None = None
1314
email: str | None = None
1415
telephone: str | None = None
1516
"""
@@ -31,6 +32,8 @@ class AutofillAddressBase:
3132
The postal code for the address.
3233
country : str | None
3334
The country of the address.
35+
country_code: str | None
36+
The code of the country.
3437
email : str | None
3538
The email address associated with the address.
3639
telephone : str | None

modules/data/about_prefs.components.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,18 @@
492492
"groups": []
493493
},
494494

495+
"form-container": {
496+
"selectorData": "form",
497+
"strategy": "id",
498+
"groups": []
499+
},
500+
501+
"save-button": {
502+
"selectorData": "save",
503+
"strategy": "id",
504+
"groups": []
505+
},
506+
495507
"reenter-new-password": {
496508
"selectorData": "pw2",
497509
"strategy": "id",

modules/page_object_autofill.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ def save_information_basic(self, autofill_info: AutofillAddressBase):
482482
"address-level2": autofill_info.address_level_2,
483483
"address-level1": autofill_info.address_level_1,
484484
"postal-code": autofill_info.postal_code,
485-
"country": autofill_info.country,
485+
"country": autofill_info.country_code,
486486
"email": autofill_info.email,
487487
"tel": autofill_info.telephone,
488488
}
@@ -547,7 +547,7 @@ def verify_autofill_data(
547547
"City": autofill_data.address_level_2,
548548
"State": autofill_data.address_level_1,
549549
"ZIP Code": autofill_data.postal_code,
550-
"Country": autofill_data.country,
550+
"Country": autofill_data.country_code,
551551
"Email": autofill_data.email,
552552
"Phone": util.normalize_regional_phone_numbers(
553553
autofill_data.telephone, region
@@ -661,7 +661,9 @@ def verify_all_fields_cleared(self):
661661
for field, value in actual_values.items():
662662
assert not value, f"Field '{field}' is not empty: Found '{value}'"
663663

664-
def clear_and_verify(self, address_autofill_popup, field_label, address_autofill_data):
664+
def clear_and_verify(
665+
self, address_autofill_popup, field_label, address_autofill_data
666+
):
665667
"""
666668
Autofills a form field, clears it, and verifies that it is empty.
667669
Parameters:
@@ -678,7 +680,10 @@ def clear_and_verify(self, address_autofill_popup, field_label, address_autofill
678680
The region code to handle localization.
679681
"""
680682
# Skip address-level1 (State) selection for DE and FR
681-
if field_label == "address-level1" and address_autofill_data.country in ["DE", "FR"]:
683+
if field_label == "address-level1" and address_autofill_data.country in [
684+
"DE",
685+
"FR",
686+
]:
682687
return
683688

684689
# Double-click a field and choose the first element from the autocomplete dropdown

0 commit comments

Comments
 (0)