Skip to content

Commit cea3c93

Browse files
authored
Merge pull request #471 from mozilla/as/cc-clear-form
Anca/l10n - CC clear form
2 parents b967f89 + dc5e504 commit cea3c93

File tree

9 files changed

+155
-31
lines changed

9 files changed

+155
-31
lines changed

l10n_CM/Unified/test_demo_ad_address_data_captured_in_doorhanger_and_stored.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
from modules.browser_object_autofill_popup import AutofillPopup
55
from modules.page_object_autofill import AddressFill
66
from modules.page_object_prefs import AboutPrefs
7-
from modules.util import Utilities, BrowserActions
8-
7+
from modules.util import BrowserActions, Utilities
98

109

1110
@pytest.fixture()
1211
def test_case():
1312
return "2888703"
1413

1514

16-
def test_demo_ad_address_data_captured_in_doorhanger_and_stored(driver: Firefox, region: str):
15+
def test_demo_ad_address_data_captured_in_doorhanger_and_stored(
16+
driver: Firefox, region: str
17+
):
1718
"""
1819
C2888703 - Verify Address data are captured in the Capture Doorhanger and stored in about:preferences
1920
"""
@@ -33,7 +34,9 @@ def test_demo_ad_address_data_captured_in_doorhanger_and_stored(driver: Firefox,
3334

3435
# containing Street Address field
3536
expected_street_add = address_autofill_data.street_address
36-
address_autofill_popup.element_has_text("address-doorhanger-street", expected_street_add)
37+
address_autofill_popup.element_has_text(
38+
"address-doorhanger-street", expected_street_add
39+
)
3740

3841
# containing City field
3942
expected_city = address_autofill_data.address_level_2
@@ -42,16 +45,24 @@ def test_demo_ad_address_data_captured_in_doorhanger_and_stored(driver: Firefox,
4245
expected_state = address_autofill_data.address_level_1
4346
if region not in ["FR", "DE"]:
4447
state_abbreviation = util.get_state_province_abbreviation(expected_state)
45-
address_autofill_popup.element_has_text("address-doorhanger-state", state_abbreviation)
48+
address_autofill_popup.element_has_text(
49+
"address-doorhanger-state", state_abbreviation
50+
)
4651

4752
# Verify Zip Code field (Different selector for DE/FR)
4853
expected_zip = address_autofill_data.postal_code
49-
zip_selector = "address-doorhanger-zip-other" if region in ["FR", "DE"] else "address-doorhanger-zip"
54+
zip_selector = (
55+
"address-doorhanger-zip-other"
56+
if region in ["FR", "DE"]
57+
else "address-doorhanger-zip"
58+
)
5059
address_autofill_popup.element_has_text(zip_selector, expected_zip)
5160

5261
# containing Country field
5362
expected_country = address_autofill_data.country
54-
address_autofill_popup.element_has_text("address-doorhanger-country", expected_country)
63+
address_autofill_popup.element_has_text(
64+
"address-doorhanger-country", expected_country
65+
)
5566

5667
# Click the "Save" button
5768
address_autofill_popup.click_doorhanger_button("save")
@@ -65,13 +76,17 @@ def test_demo_ad_address_data_captured_in_doorhanger_and_stored(driver: Firefox,
6576
elements = about_prefs.get_elements("saved-addresses-values")
6677

6778
# Expected values for verification
68-
expected_values = [expected_street_add, expected_city, expected_zip, expected_country]
79+
expected_values = [
80+
expected_street_add,
81+
expected_city,
82+
expected_zip,
83+
expected_country,
84+
]
6985
if region not in ["FR", "DE"]:
7086
expected_values.insert(2, expected_state)
7187

7288
# Check if all expected values exist in any saved address
7389
found_address_data = any(
74-
all(value in element.text for value in expected_values)
75-
for element in elements
90+
all(value in element.text for value in expected_values) for element in elements
7691
)
77-
assert found_address_data, "Street, city, state (if applicable), zip, or country were not found in any of the address entries!"
92+
assert found_address_data, "Street, city, state (if applicable), zip, or country were not found in any of the address entries!"
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 import AboutPrefs, CreditCardFill
6+
from modules.util import BrowserActions, Utilities
7+
8+
9+
@pytest.fixture()
10+
def test_case():
11+
return "2886602"
12+
13+
14+
def test_cc_clear_form(driver: Firefox):
15+
"""
16+
C2886602 - Verify that clearing the form from any field results in all fields being emptied, regardless of the
17+
field from which the clear action was triggered.
18+
"""
19+
20+
# Initialize objects
21+
util = Utilities()
22+
about_prefs = AboutPrefs(driver, category="privacy")
23+
about_prefs_cc_popup = AboutPrefs(driver)
24+
browser_action_obj = BrowserActions(driver)
25+
credit_card_fill_obj = CreditCardFill(driver)
26+
autofill_popup = AutofillPopup(driver)
27+
28+
# Save a credit card in about:preferences
29+
about_prefs.open()
30+
iframe = about_prefs.get_saved_payments_popup_iframe()
31+
browser_action_obj.switch_to_iframe_context(iframe)
32+
credit_card_sample_data = util.fake_credit_card_data()
33+
about_prefs_cc_popup.click_on(
34+
"panel-popup-button", labels=["autofill-manage-add-button"]
35+
)
36+
about_prefs.fill_cc_panel_information(credit_card_sample_data)
37+
38+
# Open credit card form page, clear form and verify all fields are empty
39+
credit_card_fill_obj.open()
40+
credit_card_fill_obj.verify_clear_form_all_fields(autofill_popup)

l10n_CM/region/CA.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"test_demo_ad_doorhanger_shown_on_valid_address_submission.py",
77
"test_demo_ad_name_org_captured_in_doorhanger_and_stored.py",
88
"test_demo_ad_address_data_captured_in_doorhanger_and_stored.py",
9-
"test_demo_cc_dropdown-presence.py"
9+
"test_demo_cc_dropdown-presence.py",
10+
"test_demo_cc_clear_form.py"
1011
]
1112
}

l10n_CM/region/DE.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"test_demo_ad_doorhanger_shown_on_valid_address_submission.py",
77
"test_demo_ad_name_org_captured_in_doorhanger_and_stored.py",
88
"test_demo_cc_dropdown-presence.py",
9-
"test_demo_ad_address_data_captured_in_doorhanger_and_stored.py"
9+
"test_demo_ad_address_data_captured_in_doorhanger_and_stored.py",
10+
"test_demo_cc_clear_form.py"
1011
]
1112
}

l10n_CM/region/FR.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"test_demo_ad_doorhanger_shown_on_valid_address_submission.py",
77
"test_demo_ad_name_org_captured_in_doorhanger_and_stored.py",
88
"test_demo_cc_dropdown-presence.py",
9-
"test_demo_ad_address_data_captured_in_doorhanger_and_stored.py"
9+
"test_demo_ad_address_data_captured_in_doorhanger_and_stored.py",
10+
"test_demo_cc_clear_form.py"
1011
]
1112
}

l10n_CM/region/US.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"test_demo_ad_doorhanger_shown_on_valid_address_submission.py",
77
"test_demo_ad_name_org_captured_in_doorhanger_and_stored.py",
88
"test_demo_cc_dropdown-presence.py",
9-
"test_demo_ad_address_data_captured_in_doorhanger_and_stored.py"
9+
"test_demo_ad_address_data_captured_in_doorhanger_and_stored.py",
10+
"test_demo_cc_clear_form.py"
1011
]
1112
}

modules/browser_object_autofill_popup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ def click_autofill_form_option(self) -> BasePage:
4949

5050
def click_clear_form_option(self) -> BasePage:
5151
"""Clicks to clear the saved form option (address or credit card)"""
52-
with self.driver.context(self.driver.CONTEXT_CHROME):
53-
self.get_element("clear-form-option").click()
52+
self.click_on("clear-form-option")
5453
return self
5554

5655
# Interaction with autocomplete list elements

modules/page_object_autofill.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,23 @@ def update_cc_exp_year(
303303
)
304304
return self
305305

306+
def verify_clear_form_all_fields(self, autofill_popup_obj: AutofillPopup):
307+
"""
308+
Clears all fields in the form by triggering the clear action from each field in turn. After each clear
309+
action, verifies that all fields are empty, regardless of which field initiated the clear.
310+
"""
311+
for field in self.fields:
312+
self.click_on("form-field", labels=[field])
313+
autofill_popup_obj.click_autofill_form_option()
314+
self.click_on("form-field", labels=[field])
315+
autofill_popup_obj.click_clear_form_option()
316+
# Verify that all fields are blank
317+
for f in self.fields:
318+
self.element_attribute_contains("form-field", "value", "", labels=[f])
319+
# Verify that the 'cc-csc' field does not trigger an autofill dropdown
320+
self.double_click("form-field", labels=["cc-csc"])
321+
autofill_popup_obj.ensure_autofill_dropdown_not_visible()
322+
306323

307324
class LoginAutofill(Autofill):
308325
"""

modules/util.py

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -403,21 +403,70 @@ def get_state_province_abbreviation(self, full_name: str) -> str:
403403
"""
404404
state_province_abbr = {
405405
# US States
406-
"Alabama": "AL", "Alaska": "AK", "Arizona": "AZ", "Arkansas": "AR", "California": "CA",
407-
"Colorado": "CO", "Connecticut": "CT", "Delaware": "DE", "Florida": "FL", "Georgia": "GA",
408-
"Hawaii": "HI", "Idaho": "ID", "Illinois": "IL", "Indiana": "IN", "Iowa": "IA",
409-
"Kansas": "KS", "Kentucky": "KY", "Louisiana": "LA", "Maine": "ME", "Maryland": "MD",
410-
"Massachusetts": "MA", "Michigan": "MI", "Minnesota": "MN", "Mississippi": "MS", "Missouri": "MO",
411-
"Montana": "MT", "Nebraska": "NE", "Nevada": "NV", "New Hampshire": "NH", "New Jersey": "NJ",
412-
"New Mexico": "NM", "New York": "NY", "North Carolina": "NC", "North Dakota": "ND", "Ohio": "OH",
413-
"Oklahoma": "OK", "Oregon": "OR", "Pennsylvania": "PA", "Rhode Island": "RI", "South Carolina": "SC",
414-
"South Dakota": "SD", "Tennessee": "TN", "Texas": "TX", "Utah": "UT", "Vermont": "VT",
415-
"Virginia": "VA", "Washington": "WA", "West Virginia": "WV", "Wisconsin": "WI", "Wyoming": "WY",
416-
406+
"Alabama": "AL",
407+
"Alaska": "AK",
408+
"Arizona": "AZ",
409+
"Arkansas": "AR",
410+
"California": "CA",
411+
"Colorado": "CO",
412+
"Connecticut": "CT",
413+
"Delaware": "DE",
414+
"Florida": "FL",
415+
"Georgia": "GA",
416+
"Hawaii": "HI",
417+
"Idaho": "ID",
418+
"Illinois": "IL",
419+
"Indiana": "IN",
420+
"Iowa": "IA",
421+
"Kansas": "KS",
422+
"Kentucky": "KY",
423+
"Louisiana": "LA",
424+
"Maine": "ME",
425+
"Maryland": "MD",
426+
"Massachusetts": "MA",
427+
"Michigan": "MI",
428+
"Minnesota": "MN",
429+
"Mississippi": "MS",
430+
"Missouri": "MO",
431+
"Montana": "MT",
432+
"Nebraska": "NE",
433+
"Nevada": "NV",
434+
"New Hampshire": "NH",
435+
"New Jersey": "NJ",
436+
"New Mexico": "NM",
437+
"New York": "NY",
438+
"North Carolina": "NC",
439+
"North Dakota": "ND",
440+
"Ohio": "OH",
441+
"Oklahoma": "OK",
442+
"Oregon": "OR",
443+
"Pennsylvania": "PA",
444+
"Rhode Island": "RI",
445+
"South Carolina": "SC",
446+
"South Dakota": "SD",
447+
"Tennessee": "TN",
448+
"Texas": "TX",
449+
"Utah": "UT",
450+
"Vermont": "VT",
451+
"Virginia": "VA",
452+
"Washington": "WA",
453+
"West Virginia": "WV",
454+
"Wisconsin": "WI",
455+
"Wyoming": "WY",
417456
# Canadian Provinces
418-
"Alberta": "AB", "British Columbia": "BC", "Manitoba": "MB", "New Brunswick": "NB",
419-
"Newfoundland and Labrador": "NL", "Nova Scotia": "NS", "Ontario": "ON", "Prince Edward Island": "PE",
420-
"Quebec": "QC", "Saskatchewan": "SK", "Northwest Territories": "NT", "Nunavut": "NU", "Yukon": "YT",
457+
"Alberta": "AB",
458+
"British Columbia": "BC",
459+
"Manitoba": "MB",
460+
"New Brunswick": "NB",
461+
"Newfoundland and Labrador": "NL",
462+
"Nova Scotia": "NS",
463+
"Ontario": "ON",
464+
"Prince Edward Island": "PE",
465+
"Quebec": "QC",
466+
"Saskatchewan": "SK",
467+
"Northwest Territories": "NT",
468+
"Nunavut": "NU",
469+
"Yukon": "YT",
421470
}
422471

423472
return state_province_abbr.get(full_name, "Not Found")

0 commit comments

Comments
 (0)