@@ -68,6 +68,30 @@ def fill_and_submit(self, data_object: CreditCardBase | AutofillAddressBase | di
68
68
self ._fill_input_element (field_name , value )
69
69
self ._click_form_button ("submit" )
70
70
71
+ def update_form_data (
72
+ self ,
73
+ sample_data : AutofillAddressBase | CreditCardBase ,
74
+ field : str ,
75
+ value : str | int ,
76
+ ):
77
+ """
78
+ Update the form field with the new value.
79
+
80
+ Arguments:
81
+ sample_data: sample data instance used to verify change.
82
+ field: field being changed.
83
+ value: value being added.
84
+ """
85
+ # updating the profile accordingly
86
+ self .update_and_save (field , value )
87
+
88
+ # autofill data
89
+ self .select_autofill_option (field )
90
+
91
+ # verifying the correct data
92
+ self .verify_form_data (sample_data )
93
+ return self
94
+
71
95
def verify_form_data (self , sample_data : CreditCardBase | AutofillAddressBase ):
72
96
"""Verify that form is filled correctly against sample data."""
73
97
if not self .field_mapping :
@@ -247,6 +271,24 @@ def fill_and_save(
247
271
self .autofill_popup .click_doorhanger_button ("save" )
248
272
return autofill_data
249
273
274
+ def update_and_save (self , field : str , value : str | int , door_hanger : bool = True ):
275
+ """
276
+ Update form with new field value and save.
277
+
278
+ Arguments:
279
+ field: field label.
280
+ value: new value to be updated.
281
+ door_hanger: bool to indication interaction with door_hanger.
282
+ """
283
+ self ._fill_input_element (field , value )
284
+ self ._click_form_button ("submit" )
285
+
286
+ if door_hanger :
287
+ if field == "cc-number" :
288
+ self .autofill_popup .click_doorhanger_button ("save" )
289
+ else :
290
+ self .autofill_popup .click_doorhanger_button ("update" )
291
+
250
292
def check_autofill_preview_for_field (
251
293
self ,
252
294
field_label : str ,
@@ -295,6 +337,7 @@ def clear_and_verify(
295
337
):
296
338
"""
297
339
Autofills a form field, clears it, and verifies that it is empty.
340
+ If sample data is present, will verify that data is filled correctly.
298
341
299
342
Arguments:
300
343
field_label : The label of the field being autofilled.
@@ -326,6 +369,33 @@ def clear_and_verify(
326
369
# Verify all fields are cleared
327
370
self .verify_all_fields_cleared ()
328
371
372
+ def generate_field_data (
373
+ self , sample_data : AutofillAddressBase | CreditCardBase , field : str , region : str
374
+ ) -> str | int :
375
+ """
376
+ Generates a new data for sample data according to field given, updates the information in the form.
377
+
378
+ Arguments:
379
+ sample_data: sample data instance being updated
380
+ field: field being updated
381
+ region: region being tested
382
+ """
383
+ faker_method = (
384
+ self .util .fake_credit_card_data
385
+ if self .__class__ == CreditCardFill
386
+ else self .util .fake_autofill_data
387
+ )
388
+ new_sample_data_value = getattr (
389
+ faker_method (country_code = region ), self .field_mapping [field ]
390
+ )
391
+ while new_sample_data_value == getattr (sample_data , self .field_mapping [field ]):
392
+ new_sample_data_value = getattr (
393
+ faker_method (country_code = region ), self .field_mapping [field ]
394
+ )
395
+
396
+ setattr (sample_data , self .field_mapping [field ], new_sample_data_value )
397
+ return new_sample_data_value
398
+
329
399
330
400
class AddressFill (Autofill ):
331
401
"""
@@ -455,91 +525,6 @@ def verify_autofill_data_on_hover(self, autofill_data: CreditCardBase):
455
525
f"Mismatched data: { (field , value )} not in { expected_values } ."
456
526
)
457
527
458
- def update_field (self , field : str , field_data : str ):
459
- """
460
- Updates a field in the form with given data.
461
-
462
- ...
463
-
464
- Parameters
465
- ----------
466
-
467
- field: str
468
- The name of the field to fill
469
-
470
- field_data: str
471
- The data to put in the field
472
- """
473
- self ._fill_input_element (field , field_data )
474
- self ._click_form_button ("submit" )
475
-
476
- def update_credit_card_information (
477
- self , field_name : str , field_data : str , save_card = False
478
- ):
479
- """
480
- Updates the credit card based on field that is to be changed by first autofilling everything then updating
481
- the field of choice then pressing submit and handling the popup.
482
- """
483
- self .update_field (field_name , field_data )
484
- self ._click_form_button ("submit" )
485
-
486
- if save_card or field_name == "cc-number" :
487
- self .autofill_popup .click_on ("doorhanger-save-button" )
488
- else :
489
- self .autofill_popup .click_on ("update-card-info-popup-button" )
490
-
491
- def verify_updated_information (
492
- self , credit_card_sample_data : CreditCardBase , field_name : str , new_data : str
493
- ) -> Autofill :
494
- """
495
- Verifies that there is only 1 profile in the popup panel, updates the credit card information and verifies all
496
- the fields according to the passed in credit card information object
497
-
498
- Attributes
499
- ----------
500
-
501
- credit_card_sample_data: CreditCardBase
502
- An instance of the fake generated data
503
-
504
- field_name: str
505
- The name of the field to update
506
-
507
- new_data: str
508
- The data to update the field with
509
- """
510
-
511
- # updating the profile accordingly
512
- self .update_credit_card_information (field_name , new_data )
513
-
514
- # autofill data
515
- self .select_autofill_option (field_name )
516
-
517
- # verifying the correct data
518
- self .verify_form_data (credit_card_sample_data )
519
- return self
520
-
521
- def update_cc (
522
- self , credit_card_sample_data : CreditCardBase , field : str
523
- ) -> Autofill :
524
- """
525
- Generates a new data for credit card according to field given, updates the credit card information in the form.
526
- """
527
- cc_mapping = {
528
- "cc-name" : "name" ,
529
- "cc-exp-month" : "expiration_month" ,
530
- "cc-exp-year" : "expiration_year" ,
531
- "cc-number" : "card_number" ,
532
- }
533
-
534
- new_cc_data = getattr (self .util .fake_credit_card_data (), cc_mapping [field ])
535
- while new_cc_data == getattr (credit_card_sample_data , cc_mapping [field ]):
536
- new_cc_data = getattr (self .util .fake_credit_card_data (), cc_mapping [field ])
537
-
538
- setattr (credit_card_sample_data , cc_mapping [field ], new_cc_data )
539
-
540
- self .verify_updated_information (credit_card_sample_data , field , new_cc_data )
541
- return self
542
-
543
528
544
529
class LoginAutofill (Autofill ):
545
530
"""
0 commit comments