Skip to content

Commit 74e28af

Browse files
authored
Merge pull request #489 from mozilla/Hani/clear_from_name_org
Hani/l10n ad - clear form from name and org
2 parents fe8c4ad + 9fb047f commit 74e28af

File tree

3 files changed

+104
-2
lines changed

3 files changed

+104
-2
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 "2888560"
12+
13+
14+
def test_demo_ad_clear_name_org(
15+
driver: Firefox,
16+
region: str,
17+
address_autofill: AddressFill,
18+
util: Utilities,
19+
autofill_popup: AutofillPopup
20+
):
21+
"""
22+
C2888560 - Verify clear functionality after selecting an entry from name/org 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+
"name",
35+
"organization"
36+
]
37+
38+
# Loop through each field and perform the autofill test
39+
for field in fields_to_test:
40+
address_autofill.clear_and_verify(autofill_popup, field, address_autofill_data)

l10n_CM/region/Unified.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
"test_demo_cc_dropdown-presence.py",
1515
"test_demo_cc_yellow_highlight.py",
1616
"test_demo_ad_yellow_highlight.py",
17-
"test_demo_ad_autofill_address_fields.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",
1820
"test_demo_ad_yellow_highlight_name_org.py",
1921
"test_demo_ad_yellow_highlight_address.py",
20-
"test_demo_ad_yellow_highlight_phone_email.py"
22+
"test_demo_ad_clear_name_org.py",
23+
"test_demo_ad_yellow_highlight_phone_email.py",
24+
"test_demo_ad_clear_name_org.py"
2125
]
2226
}

modules/page_object_autofill.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,64 @@ def autofill_and_verify(
590590
self.double_click("form-field", labels=[field_label])
591591
address_autofill_popup.click_clear_form_option()
592592

593+
def verify_all_fields_cleared(self):
594+
"""
595+
Verifies that all autofill fields are empty.
596+
"""
597+
field_mapping = {
598+
"Name": "name-field",
599+
"Organization": "org-field",
600+
"Street Address": "street-field",
601+
"City": "add-level2-field",
602+
"State": "add-level1-field",
603+
"ZIP Code": "zip-field",
604+
"Country": "country-field",
605+
"Email": "email-field",
606+
"Phone": "phone-field",
607+
}
608+
609+
# Get actual values from web elements
610+
actual_values = {
611+
field: self.get_element(locator).get_attribute("value")
612+
for field, locator in field_mapping.items()
613+
}
614+
615+
# Validate each field is empty
616+
for field, value in actual_values.items():
617+
assert not value, f"Field '{field}' is not empty: Found '{value}'"
618+
619+
def clear_and_verify(self, address_autofill_popup, field_label, address_autofill_data):
620+
"""
621+
Autofills a form field, clears it, and verifies that it is empty.
622+
Parameters:
623+
----------
624+
address_autofill : AddressFill
625+
The address autofill handler.
626+
address_autofill_popup : AutofillPopup
627+
The popup handler for autofill suggestions.
628+
field_label : str
629+
The label of the field being autofilled.
630+
address_autofill_data : dict
631+
The generated autofill data for verification.
632+
region : str
633+
The region code to handle localization.
634+
"""
635+
# Skip address-level1 (State) selection for DE and FR
636+
if field_label == "address-level1" and address_autofill_data.country in ["DE", "FR"]:
637+
return
638+
639+
# Double-click a field and choose the first element from the autocomplete dropdown
640+
self.double_click("form-field", labels=[field_label])
641+
first_item = address_autofill_popup.get_nth_element(1)
642+
address_autofill_popup.click_on(first_item)
643+
644+
# Clear form autofill
645+
self.double_click("form-field", labels=[field_label])
646+
address_autofill_popup.click_clear_form_option()
647+
648+
# Verify all fields are cleared
649+
self.verify_all_fields_cleared()
650+
593651

594652
class TextAreaFormAutofill(Autofill):
595653
"""

0 commit comments

Comments
 (0)