Skip to content

Commit 70c03a4

Browse files
philimon-resetvsangereanMOZ
authored andcommitted
amazon address field working
1 parent 40cbb10 commit 70c03a4

File tree

4 files changed

+68
-22
lines changed

4 files changed

+68
-22
lines changed

l10n_CM/Unified/conftest.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def prefs_list(add_to_prefs_list: List[tuple[str, str | bool]], region: str):
4040
def site_data():
4141
# live_site = os.environ.get("FX_SITE", None)
4242
# un comment to test a live site form
43-
live_site = "walmart/walmart_ad"
43+
live_site = "amazon/amazon_ad"
4444
if live_site:
4545
path_to_site = parent_dir + "/constants/"
4646
with open(path_to_site + live_site + ".json", "r") as fp:
@@ -65,17 +65,31 @@ def field_mapping(site_data):
6565

6666

6767
@pytest.fixture()
68-
def address_autofill(driver, url_template, fields, field_mapping):
69-
return AddressFill(
68+
def form_field(site_data):
69+
selector = site_data.get("form_field", None)
70+
return (
71+
{"form-field": {"selectorData": selector, "strategy": "css", "groups": []}}
72+
if selector
73+
else {}
74+
)
75+
76+
77+
@pytest.fixture()
78+
def address_autofill(driver, url_template, fields, field_mapping, form_field):
79+
af = AddressFill(
7080
driver, url_template=url_template, field_mapping=field_mapping, fields=fields
7181
)
82+
af.elements |= form_field
83+
return af
7284

7385

7486
@pytest.fixture()
75-
def credit_card_autofill(driver, url_template, fields, field_mapping):
76-
return CreditCardFill(
87+
def credit_card_autofill(driver, url_template, fields, field_mapping, form_field):
88+
cf = CreditCardFill(
7789
driver, url_template=url_template, field_mapping=field_mapping, fields=fields
7890
)
91+
cf.elements |= form_field
92+
return cf
7993

8094

8195
@pytest.fixture()

l10n_CM/Unified/test_demo_ad_4a_highlight_name_org_fields.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ def test_address_yellow_highlight_on_name_organization_fields(
3030
address_autofill.open()
3131

3232
# Double click inside name field and select a saved address entry from the dropdown
33-
address_autofill.click_form_field("name")
33+
if address_autofill.is_field_present("name"):
34+
address_autofill.click_form_field("name")
35+
else:
36+
address_autofill.click_form_field("given_name")
3437
autofill_popup.ensure_autofill_dropdown_visible()
3538

3639
# Click on the first element from the autocomplete dropdown
3740
autofill_popup.select_nth_element(1)
3841

39-
field_to_test = ["name", "organization"]
42+
field_to_test = ["given_name", "family_name", "name", "organization"]
4043
# Verify the name and organization fields are highlighted
4144
address_autofill.verify_field_highlight(
4245
fields_to_test=field_to_test,
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
{
22
"url": "http://127.0.0.1:8000/amazon.html",
33
"field_mapping": {
4-
"name": "name",
5-
"street_address": "address-ui-widgets-enterAddressLine1",
6-
"address_level_2": "address-ui-widgets-enterAddressLine2",
7-
"address_level_1": "address-ui-widgets-enterAddressCity",
8-
"postal_code": "address-ui-widgets-enterAddressPostalCode",
9-
"telephone": "tel"
4+
"name": "152ffe55-1b63-4bf7-a43c-21d217d8aca1",
5+
"street_address": "33198fca-ddab-40a0-bc03-8b6f83bc3a98",
6+
"address_level_2": "bf3bb4bd-06fc-493b-a8d5-7c2c31db66cb",
7+
"address_level_1": "be3c9233-db95-4cf4-aa79-9f3c9e0bbe5c",
8+
"postal_code": "543e09ec-34d0-4f72-846c-5ae35a323ba8",
9+
"telephone": "581c61d2-1257-4da2-9899-9d18e92b6fc4"
1010
},
11+
"form_field": "*[data-moz-autofill-inspect-id='{name}']",
1112
"fields": [
12-
"name",
13-
"address-ui-widgets-enterAddressLine1",
14-
"address-ui-widgets-enterAddressLine2",
15-
"address-ui-widgets-enterAddressCity",
16-
"address-ui-widgets-enterAddressPostalCode",
17-
"tel"
13+
"152ffe55-1b63-4bf7-a43c-21d217d8aca1",
14+
"581c61d2-1257-4da2-9899-9d18e92b6fc4",
15+
"bf3bb4bd-06fc-493b-a8d5-7c2c31db66cb",
16+
"be3c9233-db95-4cf4-aa79-9f3c9e0bbe5c",
17+
"543e09ec-34d0-4f72-846c-5ae35a323ba8",
18+
"33198fca-ddab-40a0-bc03-8b6f83bc3a98"
1819
]
1920
}

modules/page_object_autofill.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@
4848
"tel",
4949
)
5050

51+
# Preview field mappings
52+
base_preview_address_mapping = {}
53+
base_preview_cc_mapping = {
54+
"name": "cc-name",
55+
"card_number": "cc-number",
56+
"expiration_month": "cc-exp-month",
57+
"expiration_year": "cc-exp-year",
58+
}
59+
5160

5261
class Autofill(BasePage):
5362
"""
@@ -57,7 +66,8 @@ class Autofill(BasePage):
5766

5867
# Default; subclasses will override
5968
field_mapping = {}
60-
fields = []
69+
fields = {}
70+
preview_fields = {}
6171

6272
URL_TEMPLATE = "https://mozilla.github.io/form-fill-examples/"
6373

@@ -377,7 +387,7 @@ def verify_autofill_data_on_hover(
377387
raise ValueError("Given preview data is incomplete.")
378388
container_data = container.get("fillMessageData", {}).get("profile", {})
379389
assert container_data, "No preview data available."
380-
assert all(field in container_data.keys() for field in self.fields), (
390+
assert all(field in container_data.keys() for field in self.preview_fields), (
381391
"Not all fields present in preview data."
382392
)
383393

@@ -395,7 +405,7 @@ def verify_autofill_data_on_hover(
395405
)
396406
)
397407
for field, value in container_data.items():
398-
if field in self.fields:
408+
if field in self.preview_fields:
399409
value = self.sanitize_preview_data(field, str(value))
400410
# Check if this value exists in our CreditCardBase | AutofillAddressBase object
401411
assert value in autofill_data.__dict__.values(), (
@@ -615,6 +625,15 @@ def __init__(
615625
field_mapping if field_mapping else base_address_field_mapping
616626
)
617627
self.fields = fields if fields else base_address_fields
628+
self.preview_fields = set(
629+
map(
630+
lambda field: base_address_field_mapping.get(field, field),
631+
self.field_mapping.keys(),
632+
)
633+
)
634+
self.preview_fields = {
635+
field for field in self.preview_fields if field is not None
636+
}
618637
self.URL_TEMPLATE = url_template if url_template else BASE_ADDRESS_URL_TEMPLATE
619638

620639

@@ -635,6 +654,15 @@ def __init__(
635654
super().__init__(driver, **kwargs)
636655
self.field_mapping = field_mapping if field_mapping else base_cc_field_mapping
637656
self.fields = fields if fields else base_cc_fields
657+
self.preview_fields = set(
658+
map(
659+
lambda field: base_preview_cc_mapping.get(field),
660+
self.field_mapping.keys(),
661+
)
662+
)
663+
self.preview_fields = {
664+
field for field in self.preview_fields if field is not None
665+
}
638666
self.URL_TEMPLATE = url_template if url_template else BASE_CC_URL_TEMPLATE
639667

640668

0 commit comments

Comments
 (0)