Skip to content

Commit c92103e

Browse files
Hani YacoubHani Yacoub
authored andcommitted
Clear from address fields
1 parent 78563ae commit c92103e

File tree

3 files changed

+103
-1
lines changed

3 files changed

+103
-1
lines changed

l10n_CM/region/Unified.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"test_demo_cc_doorhanger_shown_on_valid_credit_card_submission.py",
1414
"test_demo_cc_dropdown_presence.py",
1515
"test_demo_ad_verify_new_address_added.py",
16-
"test_demo_ad_yellow_highlight_phone_email.py"
16+
"test_demo_ad_yellow_highlight_phone_email.py",
17+
"test_demo_ad_clear_address_fields.py"
1718
]
1819
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 "2888565"
12+
13+
14+
def test_demo_ad_clear_address_fields(
15+
driver: Firefox,
16+
region: str,
17+
address_autofill: AddressFill,
18+
util: Utilities,
19+
autofill_popup: AutofillPopup
20+
):
21+
"""
22+
C2888565 - Verify clear functionality after selecting an entry from address fields
23+
"""
24+
# Create fake data and fill it in
25+
address_autofill.open()
26+
address_autofill_data = util.fake_autofill_data(region)
27+
address_autofill.save_information_basic(address_autofill_data)
28+
29+
# Click the "Save" button
30+
autofill_popup.click_doorhanger_button("save")
31+
32+
# List of field labels to be autofilled and verified
33+
fields_to_test = [
34+
"street-address",
35+
"address-level2",
36+
"address-level1", # This will be skipped for DE/FR
37+
"postal-code",
38+
"country"
39+
]
40+
41+
# Loop through each field and perform the autofill test
42+
for field in fields_to_test:
43+
address_autofill.clear_and_verify(autofill_popup, field, address_autofill_data)

modules/page_object_autofill.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,64 @@ def verify_field_yellow_highlights(
569569
expected_highlighted_fields=expected_highlighted_fields,
570570
)
571571

572+
def verify_all_fields_cleared(self):
573+
"""
574+
Verifies that all autofill fields are empty.
575+
"""
576+
field_mapping = {
577+
"Name": "name-field",
578+
"Organization": "org-field",
579+
"Street Address": "street-field",
580+
"City": "add-level2-field",
581+
"State": "add-level1-field",
582+
"ZIP Code": "zip-field",
583+
"Country": "country-field",
584+
"Email": "email-field",
585+
"Phone": "phone-field",
586+
}
587+
588+
# Get actual values from web elements
589+
actual_values = {
590+
field: self.get_element(locator).get_attribute("value")
591+
for field, locator in field_mapping.items()
592+
}
593+
594+
# Validate each field is empty
595+
for field, value in actual_values.items():
596+
assert not value, f"Field '{field}' is not empty: Found '{value}'"
597+
598+
def clear_and_verify(self, address_autofill_popup, field_label, address_autofill_data):
599+
"""
600+
Autofills a form field, clears it, and verifies that it is empty.
601+
Parameters:
602+
----------
603+
address_autofill : AddressFill
604+
The address autofill handler.
605+
address_autofill_popup : AutofillPopup
606+
The popup handler for autofill suggestions.
607+
field_label : str
608+
The label of the field being autofilled.
609+
address_autofill_data : dict
610+
The generated autofill data for verification.
611+
region : str
612+
The region code to handle localization.
613+
"""
614+
# Skip address-level1 (State) selection for DE and FR
615+
if field_label == "address-level1" and address_autofill_data.country in ["DE", "FR"]:
616+
return
617+
618+
# Double-click a field and choose the first element from the autocomplete dropdown
619+
self.double_click("form-field", labels=[field_label])
620+
first_item = address_autofill_popup.get_nth_element(1)
621+
address_autofill_popup.click_on(first_item)
622+
623+
# Clear form autofill
624+
self.double_click("form-field", labels=[field_label])
625+
address_autofill_popup.click_clear_form_option()
626+
627+
# Verify all fields are cleared
628+
self.verify_all_fields_cleared()
629+
572630

573631
class TextAreaFormAutofill(Autofill):
574632
"""

0 commit comments

Comments
 (0)