@@ -590,6 +590,64 @@ def autofill_and_verify(
590
590
self .double_click ("form-field" , labels = [field_label ])
591
591
address_autofill_popup .click_clear_form_option ()
592
592
593
+ def verify_all_fields_cleared (self ):
594
+ """
595
+ Verifies that all autofill fields are empty.
596
+ """
597
+ field_mapping = {
598
+ "Name" : "name-field" ,
599
+ "Organization" : "org-field" ,
600
+ "Street Address" : "street-field" ,
601
+ "City" : "add-level2-field" ,
602
+ "State" : "add-level1-field" ,
603
+ "ZIP Code" : "zip-field" ,
604
+ "Country" : "country-field" ,
605
+ "Email" : "email-field" ,
606
+ "Phone" : "phone-field" ,
607
+ }
608
+
609
+ # Get actual values from web elements
610
+ actual_values = {
611
+ field : self .get_element (locator ).get_attribute ("value" )
612
+ for field , locator in field_mapping .items ()
613
+ }
614
+
615
+ # Validate each field is empty
616
+ for field , value in actual_values .items ():
617
+ assert not value , f"Field '{ field } ' is not empty: Found '{ value } '"
618
+
619
+ def clear_and_verify (self , address_autofill_popup , field_label , address_autofill_data ):
620
+ """
621
+ Autofills a form field, clears it, and verifies that it is empty.
622
+ Parameters:
623
+ ----------
624
+ address_autofill : AddressFill
625
+ The address autofill handler.
626
+ address_autofill_popup : AutofillPopup
627
+ The popup handler for autofill suggestions.
628
+ field_label : str
629
+ The label of the field being autofilled.
630
+ address_autofill_data : dict
631
+ The generated autofill data for verification.
632
+ region : str
633
+ The region code to handle localization.
634
+ """
635
+ # Skip address-level1 (State) selection for DE and FR
636
+ if field_label == "address-level1" and address_autofill_data .country in ["DE" , "FR" ]:
637
+ return
638
+
639
+ # Double-click a field and choose the first element from the autocomplete dropdown
640
+ self .double_click ("form-field" , labels = [field_label ])
641
+ first_item = address_autofill_popup .get_nth_element (1 )
642
+ address_autofill_popup .click_on (first_item )
643
+
644
+ # Clear form autofill
645
+ self .double_click ("form-field" , labels = [field_label ])
646
+ address_autofill_popup .click_clear_form_option ()
647
+
648
+ # Verify all fields are cleared
649
+ self .verify_all_fields_cleared ()
650
+
593
651
594
652
class TextAreaFormAutofill (Autofill ):
595
653
"""
0 commit comments