@@ -146,6 +146,7 @@ def click_form_field(self, attr_name: str):
146
146
"""Click the form field given the attribute name."""
147
147
field = self .field_mapping .get (attr_name , None )
148
148
if field :
149
+ self .get_element ("form-field" , labels = [field ]).clear ()
149
150
self .double_click ("form-field" , labels = [field ])
150
151
else :
151
152
logging .warning (f"The field: { attr_name } is not available in the site." )
@@ -236,12 +237,14 @@ def verify_form_data(self, sample_data: CreditCardBase | AutofillAddressBase):
236
237
autofilled_field
237
238
).first_selected_option .text
238
239
if (
239
- field_name == "address-level1 "
240
+ attr_name == "address_level_1 "
240
241
and autofilled_field_value != expected_value
241
242
):
242
243
expected_value = self .util .get_state_province_abbreviation (
243
244
expected_value
244
245
)
246
+ elif attr_name == "expiration_date" and len (autofilled_field_value ) > 5 :
247
+ autofilled_field_value = autofilled_field_value .replace ("20" , "" )
245
248
assert expected_value in autofilled_field_value , (
246
249
f"{ autofilled_field_value } is different from { expected_value } "
247
250
)
@@ -282,6 +285,7 @@ def verify_field_autofill_dropdown(
282
285
if field :
283
286
autofill_field = self .get_element ("form-field" , labels = [field ])
284
287
if autofill_field .tag_name .lower () != "select" :
288
+ autofill_field .clear ()
285
289
# more general way of activating the dropdown
286
290
self .double_click ("form-field" , labels = [field ])
287
291
autofill_field .send_keys ("" )
@@ -370,13 +374,14 @@ def is_yellow_highlight(rgb_tuple):
370
374
if field :
371
375
autofill_field = self .get_element ("form-field" , labels = [field ])
372
376
if autofill_field .tag_name .lower () != "select" :
377
+ autofill_field .clear ()
373
378
# Focus the field so the highlight is visible
374
379
self .click_on ("form-field" , labels = [field ])
375
380
376
381
# Get all colors in the field
377
382
selector = self .get_selector ("form-field" , labels = [field ])
378
383
colors = self .browser_actions .get_all_colors_in_element (selector )
379
- logging .info (f"Colors found in '{ field } ': { colors } " )
384
+ logging .info (f"Colors found in '{ field_name } ': { colors } " )
380
385
381
386
# Check the highlight
382
387
is_field_highlighted = any (
@@ -387,20 +392,24 @@ def is_yellow_highlight(rgb_tuple):
387
392
# Assert based on expectation
388
393
if should_be_highlighted :
389
394
assert is_field_highlighted , (
390
- f"Expected yellow highlight on '{ field } ', but none found."
395
+ f"Expected yellow highlight on '{ field_name } ', but none found."
391
396
)
392
- logging .info (f"Yellow highlight found in '{ field } '." )
397
+ logging .info (f"Yellow highlight found in '{ field_name } '." )
393
398
else :
394
399
assert not is_field_highlighted , (
395
- f"Expected NO yellow highlight on '{ field } ', but found one."
400
+ f"Expected NO yellow highlight on '{ field_name } ', but found one."
401
+ )
402
+ logging .info (
403
+ f"No yellow highlight in '{ field_name } ', as expected."
396
404
)
397
- logging .info (f"No yellow highlight in '{ field } ', as expected." )
398
405
else :
399
406
logging .info (
400
- f"Field: { field } is a select element. No autofill option."
407
+ f"Field: { field_name } is a select element. No autofill option."
401
408
)
402
409
else :
403
- logging .warning (f"The field: { field } is not available in the site." )
410
+ logging .warning (
411
+ f"The field: { field_name } is not available in the site."
412
+ )
404
413
405
414
return self
406
415
@@ -470,7 +479,7 @@ def sanitize_preview_data(self, field, value):
470
479
value = value [- 4 :]
471
480
elif field == "cc-exp-year" :
472
481
value = value [- 2 :]
473
- elif value [0 ] == "+" :
482
+ elif field == "tel" or value [0 ] == "+" :
474
483
value = self .util .normalize_phone_number (value )
475
484
return value
476
485
@@ -485,6 +494,7 @@ def select_autofill_option(self, field, index: int = 1):
485
494
"""
486
495
autofill_field = self .get_element ("form-field" , labels = [field ])
487
496
if autofill_field .tag_name .lower () != "select" :
497
+ autofill_field .clear ()
488
498
self .double_click ("form-field" , labels = [field ])
489
499
self .autofill_popup .ensure_autofill_dropdown_visible ()
490
500
self .autofill_popup .select_nth_element (index )
@@ -554,6 +564,7 @@ def check_autofill_preview_for_field(
554
564
if field :
555
565
autofill_field = self .get_element ("form-field" , labels = [field ])
556
566
if autofill_field .tag_name .lower () != "select" :
567
+ autofill_field .clear ()
557
568
self .double_click ("form-field" , labels = [field ])
558
569
self .autofill_popup .ensure_autofill_dropdown_visible ()
559
570
self .autofill_popup .hover ("select-form-option" )
@@ -609,6 +620,7 @@ def clear_and_verify(
609
620
if field :
610
621
autofill_field = self .get_element ("form-field" , labels = [field ])
611
622
if autofill_field .tag_name .lower () != "select" :
623
+ autofill_field .clear ()
612
624
# Double-click a field and choose the first element from the autocomplete dropdown
613
625
self .double_click ("form-field" , labels = [field ])
614
626
self .autofill_popup .ensure_autofill_dropdown_visible ()
0 commit comments