Skip to content

Commit be49f08

Browse files
authored
Merge pull request #468 from mozilla/Hani/add_doorhanger_captures_address_data
Hani/Demo address data captured in doorhanger and stored
2 parents 4ca442d + 5e573dd commit be49f08

File tree

8 files changed

+190
-3
lines changed

8 files changed

+190
-3
lines changed

SELECTOR_INFO.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,48 @@ Description: Save address doorhanger organization section
13671367
Location: Address bar
13681368
Path to .json: modules/data/autofill_popup.components.json
13691369
```
1370+
```
1371+
Selector Name: address-doorhanger-street
1372+
Selector Data: "div.address-save-update-row-container:nth-of-type(1) div p:nth-of-type(3) span"
1373+
Description: Save address doorhanger street address section
1374+
Location: Address bar
1375+
Path to .json: modules/data/autofill_popup.components.json
1376+
```
1377+
```
1378+
Selector Name: address-doorhanger-city
1379+
Selector Data: "div.address-save-update-row-container:nth-of-type(1) div p:nth-of-type(4) span:nth-of-type(1)"
1380+
Description: Save address doorhanger city section
1381+
Location: Address bar
1382+
Path to .json: modules/data/autofill_popup.components.json
1383+
```
1384+
```
1385+
Selector Name: address-doorhanger-state
1386+
Selector Data: "div.address-save-update-row-container:nth-of-type(1) div p:nth-of-type(4) span:nth-of-type(3)"
1387+
Description: Save address doorhanger state section
1388+
Location: Address bar
1389+
Path to .json: modules/data/autofill_popup.components.json
1390+
```
1391+
```
1392+
Selector Name: address-doorhanger-zip
1393+
Selector Data: "div.address-save-update-row-container:nth-of-type(1) div p:nth-of-type(4) span:nth-of-type(5)"
1394+
Description: Save address doorhanger zip section for US and CA
1395+
Location: Address bar
1396+
Path to .json: modules/data/autofill_popup.components.json
1397+
```
1398+
```
1399+
Selector Name: address-doorhanger-zip-other
1400+
Selector Data: "selectorData": "div.address-save-update-row-container:nth-of-type(1) div p:nth-of-type(4) span:nth-of-type(3)",
1401+
Description: Save address doorhanger zip section for other regions
1402+
Location: Address bar
1403+
Path to .json: modules/data/autofill_popup.components.json
1404+
```
1405+
```
1406+
Selector Name: address-doorhanger-country
1407+
Selector Data: "div.address-save-update-row-container:nth-of-type(1) div p:nth-of-type(5) span"
1408+
Description: Save address doorhanger country section
1409+
Location: Address bar
1410+
Path to .json: modules/data/autofill_popup.components.json
1411+
```
13701412
#### context_menu
13711413
```
13721414
Selector Name: context-menu-search-selected-text
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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.page_object_prefs import AboutPrefs
7+
from modules.util import Utilities, BrowserActions
8+
9+
10+
11+
@pytest.fixture()
12+
def test_case():
13+
return "2888703"
14+
15+
16+
def test_demo_ad_address_data_captured_in_doorhanger_and_stored(driver: Firefox, region: str):
17+
"""
18+
C2888703 - Verify Address data are captured in the Capture Doorhanger and stored in about:preferences
19+
"""
20+
# instantiate objects
21+
address_autofill = AddressFill(driver)
22+
address_autofill_popup = AutofillPopup(driver)
23+
util = Utilities()
24+
browser_action_obj = BrowserActions(driver)
25+
26+
# create fake data and fill it in
27+
address_autofill.open()
28+
address_autofill_data = util.fake_autofill_data(region)
29+
address_autofill.save_information_basic(address_autofill_data)
30+
31+
# The "Save address?" doorhanger is displayed
32+
address_autofill_popup.element_visible("address-save-doorhanger")
33+
34+
# containing Street Address field
35+
expected_street_add = address_autofill_data.street_address
36+
address_autofill_popup.element_has_text("address-doorhanger-street", expected_street_add)
37+
38+
# containing City field
39+
expected_city = address_autofill_data.address_level_2
40+
address_autofill_popup.element_has_text("address-doorhanger-city", expected_city)
41+
42+
expected_state = address_autofill_data.address_level_1
43+
if region not in ["FR", "DE"]:
44+
state_abbreviation = util.get_state_province_abbreviation(expected_state)
45+
address_autofill_popup.element_has_text("address-doorhanger-state", state_abbreviation)
46+
47+
# Verify Zip Code field (Different selector for DE/FR)
48+
expected_zip = address_autofill_data.postal_code
49+
zip_selector = "address-doorhanger-zip-other" if region in ["FR", "DE"] else "address-doorhanger-zip"
50+
address_autofill_popup.element_has_text(zip_selector, expected_zip)
51+
52+
# containing Country field
53+
expected_country = address_autofill_data.country
54+
address_autofill_popup.element_has_text("address-doorhanger-country", expected_country)
55+
56+
# Click the "Save" button
57+
address_autofill_popup.click_doorhanger_button("save")
58+
59+
# Navigate to about:preferences#privacy => "Autofill" section
60+
about_prefs = AboutPrefs(driver, category="privacy").open()
61+
iframe = about_prefs.get_save_addresses_popup_iframe()
62+
browser_action_obj.switch_to_iframe_context(iframe)
63+
64+
# Verify saved addresses
65+
elements = about_prefs.get_elements("saved-addresses-values")
66+
67+
# Expected values for verification
68+
expected_values = [expected_street_add, expected_city, expected_zip, expected_country]
69+
if region not in ["FR", "DE"]:
70+
expected_values.insert(2, expected_state)
71+
72+
# Check if all expected values exist in any saved address
73+
found_address_data = any(
74+
all(value in element.text for value in expected_values)
75+
for element in elements
76+
)
77+
assert found_address_data, "Street, city, state (if applicable), zip, or country were not found in any of the address entries!"

l10n_CM/region/CA.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"test_demo_cc_add_new_credit_card.py",
66
"test_demo_ad_doorhanger_shown_on_valid_address_submission.py",
77
"test_demo_ad_name_org_captured_in_doorhanger_and_stored.py",
8+
"test_demo_ad_address_data_captured_in_doorhanger_and_stored.py",
89
"test_demo_cc_dropdown-presence.py"
910
]
1011
}

l10n_CM/region/DE.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"test_demo_cc_add_new_credit_card.py",
66
"test_demo_ad_doorhanger_shown_on_valid_address_submission.py",
77
"test_demo_ad_name_org_captured_in_doorhanger_and_stored.py",
8-
"test_demo_cc_dropdown-presence.py"
8+
"test_demo_cc_dropdown-presence.py",
9+
"test_demo_ad_address_data_captured_in_doorhanger_and_stored.py"
910
]
1011
}

l10n_CM/region/FR.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"test_demo_cc_add_new_credit_card.py",
66
"test_demo_ad_doorhanger_shown_on_valid_address_submission.py",
77
"test_demo_ad_name_org_captured_in_doorhanger_and_stored.py",
8-
"test_demo_cc_dropdown-presence.py"
8+
"test_demo_cc_dropdown-presence.py",
9+
"test_demo_ad_address_data_captured_in_doorhanger_and_stored.py"
910
]
1011
}

l10n_CM/region/US.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"test_demo_cc_add_new_credit_card.py",
66
"test_demo_ad_doorhanger_shown_on_valid_address_submission.py",
77
"test_demo_ad_name_org_captured_in_doorhanger_and_stored.py",
8-
"test_demo_cc_dropdown-presence.py"
8+
"test_demo_cc_dropdown-presence.py",
9+
"test_demo_ad_address_data_captured_in_doorhanger_and_stored.py"
910
]
1011
}

modules/data/autofill_popup.components.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,42 @@
9595
"selectorData": "div.address-save-update-row-container:nth-of-type(1) div p:nth-of-type(2) span",
9696
"strategy": "css",
9797
"groups": []
98+
},
99+
100+
"address-doorhanger-street": {
101+
"selectorData": "div.address-save-update-row-container:nth-of-type(1) div p:nth-of-type(3) span",
102+
"strategy": "css",
103+
"groups": []
104+
},
105+
106+
"address-doorhanger-city": {
107+
"selectorData": "div.address-save-update-row-container:nth-of-type(1) div p:nth-of-type(4) span:nth-of-type(1)",
108+
"strategy": "css",
109+
"groups": []
110+
},
111+
112+
"address-doorhanger-state": {
113+
"selectorData": "div.address-save-update-row-container:nth-of-type(1) div p:nth-of-type(4) span:nth-of-type(3)",
114+
"strategy": "css",
115+
"groups": []
116+
},
117+
118+
"address-doorhanger-zip": {
119+
"selectorData": "div.address-save-update-row-container:nth-of-type(1) div p:nth-of-type(4) span:nth-of-type(5)",
120+
"strategy": "css",
121+
"groups": []
122+
},
123+
124+
"address-doorhanger-zip-other": {
125+
"selectorData": "div.address-save-update-row-container:nth-of-type(1) div p:nth-of-type(4) span:nth-of-type(3)",
126+
"strategy": "css",
127+
"groups": []
128+
},
129+
130+
"address-doorhanger-country": {
131+
"selectorData": "div.address-save-update-row-container:nth-of-type(1) div p:nth-of-type(5) span",
132+
"strategy": "css",
133+
"groups": []
98134
}
99135
}
100136

modules/util.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,34 @@ def get_all_attributes(self, driver: Firefox, item: WebElement) -> str:
394394
ret_val += f"{attribute}: {value}\n"
395395
return ret_val
396396

397+
def get_state_province_abbreviation(self, full_name: str) -> str:
398+
"""
399+
Returns the abbreviation for a given state, province, or region full name.
400+
401+
:param full_name: The full name of the state, province, or region.
402+
:return: The corresponding abbreviation or "Not Found" if not in the dictionary.
403+
"""
404+
state_province_abbr = {
405+
# 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+
417+
# 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",
421+
}
422+
423+
return state_province_abbr.get(full_name, "Not Found")
424+
397425

398426
class BrowserActions:
399427
"""

0 commit comments

Comments
 (0)