@@ -28,7 +28,7 @@ class Autofill(BasePage):
28
28
def __init__ (self , driver : Firefox , ** kwargs ):
29
29
super ().__init__ (driver , ** kwargs )
30
30
self .driver = driver
31
- self .ba = BrowserActions (self .driver )
31
+ self .browser_actions = BrowserActions (self .driver )
32
32
self .util = Utilities ()
33
33
self .autofill_popup = AutofillPopup (self .driver )
34
34
@@ -42,7 +42,7 @@ def _fill_input_element(self, field_name: str, term: str):
42
42
term: The string to be sent to the input field
43
43
"""
44
44
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 )
46
46
47
47
def _click_form_button (self , field_name ):
48
48
"""Clicks submit on the form"""
@@ -55,6 +55,8 @@ def fill_and_submit(self, data_object: CreditCardBase | AutofillAddressBase | di
55
55
data_object: object containing autofill data.
56
56
"""
57
57
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.
58
60
raise NotImplementedError (
59
61
"Method should only be called in inherited classes."
60
62
)
@@ -95,10 +97,20 @@ def update_form_data(
95
97
def verify_form_data (self , sample_data : CreditCardBase | AutofillAddressBase ):
96
98
"""Verify that form is filled correctly against sample data."""
97
99
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.
98
102
raise NotImplementedError (
99
103
"Method should only be called in inherited classes."
100
104
)
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
+ ]
101
111
for attr_name , field_name in self .field_mapping .items ():
112
+ if non_us_ca_address and field_name == "address-level1" :
113
+ continue
102
114
if field_name != "cc-csc" :
103
115
expected_value = getattr (sample_data , attr_name , None )
104
116
self .element_attribute_contains (
@@ -121,6 +133,8 @@ def verify_field_autofill_dropdown(
121
133
"""
122
134
123
135
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.
124
138
raise NotImplementedError (
125
139
"Method should only be called in inherited classes."
126
140
)
@@ -129,7 +143,7 @@ def verify_field_autofill_dropdown(
129
143
fields_to_test = self .fields
130
144
131
145
# 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 :
133
147
fields_to_test .remove ("address-level1" )
134
148
135
149
# Check fields that SHOULD trigger the autofill dropdown
@@ -167,14 +181,16 @@ def verify_field_highlight(
167
181
"""
168
182
169
183
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.
170
186
raise NotImplementedError (
171
187
"Method should only be called in inherited classes."
172
188
)
173
189
174
190
if fields_to_test is None :
175
191
fields_to_test = self .fields
176
192
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 :
178
194
fields_to_test .remove ("address-level1" )
179
195
180
196
if expected_highlighted_fields is None :
@@ -203,7 +219,7 @@ def is_yellow_highlight(rgb_tuple):
203
219
204
220
# Get all colors in the field
205
221
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 )
207
223
logging .info (f"Colors found in '{ field_name } ': { colors } " )
208
224
209
225
# Check the highlight
@@ -242,6 +258,8 @@ def verify_autofill_data_on_hover(
242
258
Abstract Method meant to be implemented in the inherited classes.
243
259
Verifies autofill data when hovering over a field.
244
260
"""
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.
245
263
raise NotImplementedError ("Method should be implemented in inherited classes." )
246
264
247
265
def select_autofill_option (self , field , index : int = 1 ):
@@ -313,7 +331,7 @@ def check_autofill_preview_for_field(
313
331
if (
314
332
self .__class__ == AddressFill
315
333
and field_label == "address-level1"
316
- and region in ["DE " , "FR " ]
334
+ and region not in ["US " , "CA " ]
317
335
):
318
336
return
319
337
self .double_click ("form-field" , labels = [field_label ])
@@ -353,7 +371,7 @@ def clear_and_verify(
353
371
"""
354
372
# Skip address-level1 (State) selection for DE and FR
355
373
if (
356
- region in ["DE " , "FR " ]
374
+ region not in ["US " , "CA " ]
357
375
and self .__class__ == AddressFill
358
376
and field_label == "address-level1"
359
377
):
0 commit comments