Skip to content

Commit 78fc3b0

Browse files
Review Fixes
1 parent a41c679 commit 78fc3b0

6 files changed

+30
-12
lines changed

l10n_CM/Unified/test_demo_ad_3a_autofill_address_fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ def test_demo_ad_autofill_address_fields(
3636

3737
# Loop through each field and perform the autofill test
3838
for field in fields_to_test:
39-
address_autofill.clear_and_verify(field, address_autofill_data)
39+
address_autofill.clear_and_verify(field, address_autofill_data, region=region)

l10n_CM/Unified/test_demo_ad_3b_autofill_name_org_fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ def test_demo_ad_autofill_name_org(
3030

3131
# Loop through each field and perform the autofill test
3232
for field in fields_to_test:
33-
address_autofill.clear_and_verify(field, address_autofill_data)
33+
address_autofill.clear_and_verify(field, address_autofill_data, region=region)

l10n_CM/Unified/test_demo_ad_3c_autofill_phone_email_fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ def test_demo_ad_autofill_phone_email(
3030

3131
# Loop through each field and perform the autofill test
3232
for field in fields_to_test:
33-
address_autofill.clear_and_verify(field, address_autofill_data)
33+
address_autofill.clear_and_verify(field, address_autofill_data, region=region)

l10n_CM/Unified/test_demo_cc_3_autofill.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_cc_autofill_from_dropdown(
3535
credit_card_data = credit_card_autofill.fill_and_save(region)
3636

3737
# Autocomplete and clear all fields
38-
credit_card_autofill.clear_and_verify_all_fields(credit_card_data, region)
38+
credit_card_autofill.clear_and_verify_all_fields(credit_card_data, region=region)
3939

4040
# Step 5: Click the csc field (cc-csc), ensure autofill popup is not present
4141
credit_card_autofill.click_on("form-field", labels=["cc-csc"]) # Use single click

modules/page_object_autofill.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Autofill(BasePage):
2828
def __init__(self, driver: Firefox, **kwargs):
2929
super().__init__(driver, **kwargs)
3030
self.driver = driver
31-
self.ba = BrowserActions(self.driver)
31+
self.browser_actions = BrowserActions(self.driver)
3232
self.util = Utilities()
3333
self.autofill_popup = AutofillPopup(self.driver)
3434

@@ -42,7 +42,7 @@ def _fill_input_element(self, field_name: str, term: str):
4242
term: The string to be sent to the input field
4343
"""
4444
form_field_element = self.get_element("form-field", labels=[field_name])
45-
self.ba.clear_and_fill(form_field_element, term, press_enter=False)
45+
self.browser_actions.clear_and_fill(form_field_element, term, press_enter=False)
4646

4747
def _click_form_button(self, field_name):
4848
"""Clicks submit on the form"""
@@ -55,6 +55,8 @@ def fill_and_submit(self, data_object: CreditCardBase | AutofillAddressBase | di
5555
data_object: object containing autofill data.
5656
"""
5757
if not self.field_mapping:
58+
# Method is meant to be called by one of the classes that inherit AutoFill (CreditCardFill or AddressFill)
59+
# Should not be called directly from an Autofill instance.
5860
raise NotImplementedError(
5961
"Method should only be called in inherited classes."
6062
)
@@ -95,10 +97,20 @@ def update_form_data(
9597
def verify_form_data(self, sample_data: CreditCardBase | AutofillAddressBase):
9698
"""Verify that form is filled correctly against sample data."""
9799
if not self.field_mapping:
100+
# Method is meant to be called by one of the classes that inherit AutoFill (CreditCardFill or AddressFill)
101+
# Should not be called directly from an Autofill instance.
98102
raise NotImplementedError(
99103
"Method should only be called in inherited classes."
100104
)
105+
106+
is_address_fill = self.__class__ == AddressFill
107+
non_us_ca_address = is_address_fill and sample_data.country_code not in [
108+
"US",
109+
"CA",
110+
]
101111
for attr_name, field_name in self.field_mapping.items():
112+
if non_us_ca_address and field_name == "address-level1":
113+
continue
102114
if field_name != "cc-csc":
103115
expected_value = getattr(sample_data, attr_name, None)
104116
self.element_attribute_contains(
@@ -121,6 +133,8 @@ def verify_field_autofill_dropdown(
121133
"""
122134

123135
if not self.field_mapping:
136+
# Method is meant to be called by one of the classes that inherit AutoFill (CreditCardFill or AddressFill)
137+
# Should not be called directly from an Autofill instance.
124138
raise NotImplementedError(
125139
"Method should only be called in inherited classes."
126140
)
@@ -129,7 +143,7 @@ def verify_field_autofill_dropdown(
129143
fields_to_test = self.fields
130144

131145
# Handle region-specific behavior
132-
if region in ["DE", "FR"] and "address-level1" in fields_to_test:
146+
if region not in ["US", "CA"] and "address-level1" in fields_to_test:
133147
fields_to_test.remove("address-level1")
134148

135149
# Check fields that SHOULD trigger the autofill dropdown
@@ -167,14 +181,16 @@ def verify_field_highlight(
167181
"""
168182

169183
if not self.field_mapping:
184+
# Method is meant to be called by one of the classes that inherit AutoFill (CreditCardFill or AddressFill)
185+
# Should not be called directly from an Autofill instance.
170186
raise NotImplementedError(
171187
"Method should only be called in inherited classes."
172188
)
173189

174190
if fields_to_test is None:
175191
fields_to_test = self.fields
176192

177-
if region in ["DE", "FR"] and "address-level1" in fields_to_test:
193+
if region not in ["US", "CA"] and "address-level1" in fields_to_test:
178194
fields_to_test.remove("address-level1")
179195

180196
if expected_highlighted_fields is None:
@@ -203,7 +219,7 @@ def is_yellow_highlight(rgb_tuple):
203219

204220
# Get all colors in the field
205221
selector = self.get_selector("form-field", labels=[field_name])
206-
colors = self.ba.get_all_colors_in_element(selector)
222+
colors = self.browser_actions.get_all_colors_in_element(selector)
207223
logging.info(f"Colors found in '{field_name}': {colors}")
208224

209225
# Check the highlight
@@ -242,6 +258,8 @@ def verify_autofill_data_on_hover(
242258
Abstract Method meant to be implemented in the inherited classes.
243259
Verifies autofill data when hovering over a field.
244260
"""
261+
# Method is meant to be called by one of the classes that inherit AutoFill (CreditCardFill or AddressFill)
262+
# Should not be called directly from an Autofill instance.
245263
raise NotImplementedError("Method should be implemented in inherited classes.")
246264

247265
def select_autofill_option(self, field, index: int = 1):
@@ -313,7 +331,7 @@ def check_autofill_preview_for_field(
313331
if (
314332
self.__class__ == AddressFill
315333
and field_label == "address-level1"
316-
and region in ["DE", "FR"]
334+
and region not in ["US", "CA"]
317335
):
318336
return
319337
self.double_click("form-field", labels=[field_label])
@@ -353,7 +371,7 @@ def clear_and_verify(
353371
"""
354372
# Skip address-level1 (State) selection for DE and FR
355373
if (
356-
region in ["DE", "FR"]
374+
region not in ["US", "CA"]
357375
and self.__class__ == AddressFill
358376
and field_label == "address-level1"
359377
):

tests/form_autofill/test_autofill_credit_card.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ def test_autofill_credit_card(
3535
credit_card_data = credit_card_autofill.fill_and_save(region)
3636

3737
# autofill from a given field and verify, repeat for all fields
38-
credit_card_autofill.clear_and_verify_all_fields(credit_card_data, region)
38+
credit_card_autofill.clear_and_verify_all_fields(credit_card_data, region=region)

0 commit comments

Comments
 (0)