Skip to content

Commit 9997061

Browse files
Hani YacoubHani Yacoub
authored andcommitted
Test demo ad address data captured in doorhanger and stored
1 parent cd2bf36 commit 9997061

File tree

8 files changed

+99
-18
lines changed

8 files changed

+99
-18
lines changed

SELECTOR_INFO.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,48 @@ Description: Save address doorhanger
13531353
Location: Address bar
13541354
Path to .json: modules/data/autofill_popup.components.json
13551355
```
1356+
```
1357+
Selector Name: address-doorhanger-street
1358+
Selector Data: "div.address-save-update-row-container:nth-of-type(1) div p:nth-of-type(3) span"
1359+
Description: Save address doorhanger street address section
1360+
Location: Address bar
1361+
Path to .json: modules/data/autofill_popup.components.json
1362+
```
1363+
```
1364+
Selector Name: address-doorhanger-city
1365+
Selector Data: "div.address-save-update-row-container:nth-of-type(1) div p:nth-of-type(4) span:nth-of-type(1)"
1366+
Description: Save address doorhanger city section
1367+
Location: Address bar
1368+
Path to .json: modules/data/autofill_popup.components.json
1369+
```
1370+
```
1371+
Selector Name: address-doorhanger-state
1372+
Selector Data: "div.address-save-update-row-container:nth-of-type(1) div p:nth-of-type(4) span:nth-of-type(3)"
1373+
Description: Save address doorhanger state section
1374+
Location: Address bar
1375+
Path to .json: modules/data/autofill_popup.components.json
1376+
```
1377+
```
1378+
Selector Name: address-doorhanger-zip
1379+
Selector Data: "div.address-save-update-row-container:nth-of-type(1) div p:nth-of-type(4) span:nth-of-type(5)"
1380+
Description: Save address doorhanger zip section for US and CA
1381+
Location: Address bar
1382+
Path to .json: modules/data/autofill_popup.components.json
1383+
```
1384+
```
1385+
Selector Name: address-doorhanger-zip-other
1386+
Selector Data: "selectorData": "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 zip section for other regions
1388+
Location: Address bar
1389+
Path to .json: modules/data/autofill_popup.components.json
1390+
```
1391+
```
1392+
Selector Name: address-doorhanger-country
1393+
Selector Data: "div.address-save-update-row-container:nth-of-type(1) div p:nth-of-type(5) span"
1394+
Description: Save address doorhanger country section
1395+
Location: Address bar
1396+
Path to .json: modules/data/autofill_popup.components.json
1397+
```
13561398
#### context_menu
13571399
```
13581400
Selector Name: context-menu-search-selected-text

l10n_CM/Unified/test_demo_ad_address_data_captured_in_doorhanger_and_stored.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from selenium.webdriver import Firefox
33

44
from modules.browser_object_autofill_popup import AutofillPopup
5-
from modules.page_object_about_pages import AboutConfig
65
from modules.page_object_autofill import AddressFill
76
from modules.page_object_prefs import AboutPrefs
87
from modules.util import Utilities, BrowserActions
@@ -22,12 +21,8 @@ def test_demo_ad_address_data_captured_in_doorhanger_and_stored(driver: Firefox,
2221
address_autofill = AddressFill(driver)
2322
address_autofill_popup = AutofillPopup(driver)
2423
util = Utilities()
25-
about_config = AboutConfig(driver)
2624
browser_action_obj = BrowserActions(driver)
2725

28-
# Change pref value of region
29-
about_config.change_config_value("browser.search.region", region)
30-
3126
# create fake data and fill it in
3227
address_autofill.open()
3328
address_autofill_data = util.fake_autofill_data(region)
@@ -44,13 +39,15 @@ def test_demo_ad_address_data_captured_in_doorhanger_and_stored(driver: Firefox,
4439
expected_city = address_autofill_data.address_level_2
4540
address_autofill_popup.element_has_text("address-doorhanger-city", expected_city)
4641

47-
# containing State/Province field
4842
expected_state = address_autofill_data.address_level_1
49-
address_autofill_popup.element_has_text("address-doorhanger-state", expected_state)
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)
5046

51-
# containing Zip code field
47+
# Verify Zip Code field (Different selector for DE/FR)
5248
expected_zip = address_autofill_data.postal_code
53-
address_autofill_popup.element_has_text("address-doorhanger-zip", expected_zip)
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)
5451

5552
# containing Country field
5653
expected_country = address_autofill_data.country
@@ -64,13 +61,17 @@ def test_demo_ad_address_data_captured_in_doorhanger_and_stored(driver: Firefox,
6461
iframe = about_prefs.get_save_addresses_popup_iframe()
6562
browser_action_obj.switch_to_iframe_context(iframe)
6663

67-
# The address saved in step 2 is listed in the "Saved addresses" modal: Street, city, state, zip and country
64+
# Verify saved addresses
6865
elements = about_prefs.get_elements("saved-addresses-values")
66+
67+
# Expected values for verification
6968
expected_values = [expected_street_add, expected_city, expected_zip, expected_country]
70-
found_name_org = any(
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(
7174
all(value in element.text for value in expected_values)
7275
for element in elements
7376
)
74-
assert (
75-
found_name_org
76-
), "Street, city, state, zip or country were not found in any of the address entries!"
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"tests": [
44
"test_demo_cc_doorhanger_shown_on_valid_credit_card_submission.py",
55
"test_demo_cc_add_new_credit_card.py",
6-
"test_demo_ad_doorhanger_shown_on_valid_address_submission.py"
6+
"test_demo_ad_doorhanger_shown_on_valid_address_submission.py",
7+
"test_demo_ad_address_data_captured_in_doorhanger_and_stored.py"
78
]
89
}

l10n_CM/region/DE.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"tests": [
44
"test_demo_cc_doorhanger_shown_on_valid_credit_card_submission.py",
55
"test_demo_cc_add_new_credit_card.py",
6-
"test_demo_ad_doorhanger_shown_on_valid_address_submission.py"
6+
"test_demo_ad_doorhanger_shown_on_valid_address_submission.py",
7+
"test_demo_ad_address_data_captured_in_doorhanger_and_stored.py"
78
]
89
}

l10n_CM/region/FR.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"tests": [
44
"test_demo_cc_doorhanger_shown_on_valid_credit_card_submission.py",
55
"test_demo_cc_add_new_credit_card.py",
6-
"test_demo_ad_doorhanger_shown_on_valid_address_submission.py"
6+
"test_demo_ad_doorhanger_shown_on_valid_address_submission.py",
7+
"test_demo_ad_address_data_captured_in_doorhanger_and_stored.py"
78
]
89
}

l10n_CM/region/US.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"tests": [
44
"test_demo_cc_doorhanger_shown_on_valid_credit_card_submission.py",
55
"test_demo_cc_add_new_credit_card.py",
6-
"test_demo_ad_doorhanger_shown_on_valid_address_submission.py"
6+
"test_demo_ad_doorhanger_shown_on_valid_address_submission.py",
7+
"test_demo_ad_address_data_captured_in_doorhanger_and_stored.py"
78
]
89
}

modules/data/autofill_popup.components.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@
109109
"groups": []
110110
},
111111

112+
"address-doorhanger-zip-other": {
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+
112118
"address-doorhanger-country": {
113119
"selectorData": "div.address-save-update-row-container:nth-of-type(1) div p:nth-of-type(5) span",
114120
"strategy": "css",

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)