Skip to content

Commit 42218ba

Browse files
creditcardfill methods moved to autofill except one
1 parent d1bb60d commit 42218ba

File tree

5 files changed

+91
-99
lines changed

5 files changed

+91
-99
lines changed

SELECTOR_INFO.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ Path to .json: modules/data/autofill_popup.components.json
13831383
```
13841384
```
13851385
Selector Name: doorhanger-save-button
1386-
Selector Data: button[label='Save'].popup-notification-primary-button
1386+
Selector Data: button[label^='Save'].popup-notification-primary-button
13871387
Description: The "Save" button
13881388
Location: Inside the autofill save doorhangers (address and credit card) that is triggered in navigation bar
13891389
Path to .json: modules/data/autofill_popup.components.json
@@ -1418,7 +1418,7 @@ Path to .json: modules/data/autofill_popup.components.json
14181418
```
14191419
```
14201420
Selector Name: doorhanger-update-button
1421-
Selector Data: "button[label='Update']"
1421+
Selector Data: "button[label^='Update']"
14221422
Description: The "Update" button
14231423
Location: Inside the autofill save addreses doorhanger that is triggered in navigation bar
14241424
Path to .json: modules/data/autofill_popup.components.json

modules/data/autofill_popup.components.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99

1010
"doorhanger-save-button": {
11-
"selectorData": "button[label='Save'].popup-notification-primary-button",
11+
"selectorData": "button[label^='Save'].popup-notification-primary-button",
1212
"strategy": "css",
1313
"groups": []
1414
},
@@ -38,7 +38,7 @@
3838
},
3939

4040
"doorhanger-update-button": {
41-
"selectorData": "button[label='Update']",
41+
"selectorData": "button[label^='Update']",
4242
"strategy": "css",
4343
"groups": []
4444
},

modules/page_object_autofill.py

Lines changed: 70 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,30 @@ def fill_and_submit(self, data_object: CreditCardBase | AutofillAddressBase | di
6868
self._fill_input_element(field_name, value)
6969
self._click_form_button("submit")
7070

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+
7195
def verify_form_data(self, sample_data: CreditCardBase | AutofillAddressBase):
7296
"""Verify that form is filled correctly against sample data."""
7397
if not self.field_mapping:
@@ -247,6 +271,24 @@ def fill_and_save(
247271
self.autofill_popup.click_doorhanger_button("save")
248272
return autofill_data
249273

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+
250292
def check_autofill_preview_for_field(
251293
self,
252294
field_label: str,
@@ -295,6 +337,7 @@ def clear_and_verify(
295337
):
296338
"""
297339
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.
298341
299342
Arguments:
300343
field_label : The label of the field being autofilled.
@@ -326,6 +369,33 @@ def clear_and_verify(
326369
# Verify all fields are cleared
327370
self.verify_all_fields_cleared()
328371

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+
329399

330400
class AddressFill(Autofill):
331401
"""
@@ -455,91 +525,6 @@ def verify_autofill_data_on_hover(self, autofill_data: CreditCardBase):
455525
f"Mismatched data: {(field, value)} not in {expected_values}."
456526
)
457527

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-
543528

544529
class LoginAutofill(Autofill):
545530
"""

tests/form_autofill/test_updating_address.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
from selenium.webdriver import Firefox, Keys
2+
from selenium.webdriver import Firefox
33

44
from modules.browser_object_autofill_popup import AutofillPopup
55
from modules.page_object import AboutPrefs
@@ -38,12 +38,10 @@ def test_update_address(
3838
# Double-click on the name field to trigger the autocomplete dropdown
3939
address_autofill.select_autofill_option("name")
4040

41-
# Add a middle name inside the Name field
42-
address_autofill.click_on("form-field", labels=["name"])
43-
address_autofill.fill_and_submit({"name": sample_data.name + " Doe"})
44-
45-
# Save the updated address
46-
autofill_popup.click_doorhanger_button("update")
41+
# Change name field value.
42+
new_name_value = sample_data.name + " Doe"
43+
setattr(sample_data, "name", new_name_value)
44+
address_autofill.update_form_data(sample_data, "name", new_name_value)
4745

4846
# Navigate to settings
4947
about_prefs_privacy.open()
@@ -56,7 +54,9 @@ def test_update_address(
5654
)
5755

5856
# Assert that "Doe" is present in updated entry
59-
found_updated_address = any("Doe" in element.text for element in saved_addresses)
57+
found_updated_address = any(
58+
new_name_value in element.text for element in saved_addresses
59+
)
6060
assert found_updated_address, (
61-
"The value 'Doe' was not found in any of the address entries."
61+
"The new name was not found in any of the address entries."
6262
)

tests/form_autofill/test_updating_credit_card.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def test_update_cc_no_dupe_name(
2626
credit_card_autofill: CreditCardFill,
2727
util: Utilities,
2828
field: str,
29+
region: str,
2930
):
3031
"""
3132
C122406, ensures that updating the credit card saves the correct information with no dupe profile for the name and expiry dates
@@ -37,6 +38,7 @@ def test_update_cc_no_dupe_name(
3738
credit_card_autofill: CreditCardFill instance
3839
util: Utilities instance
3940
field: credit card field being checked
41+
region: region being tested.
4042
"""
4143
# navigate to credit card form page
4244
credit_card_autofill.open()
@@ -48,7 +50,12 @@ def test_update_cc_no_dupe_name(
4850
credit_card_autofill.select_autofill_option(field)
4951

5052
# updating the name of the cc holder
51-
credit_card_autofill.update_cc(credit_card_sample_data, field)
53+
new_field_value = credit_card_autofill.generate_field_data(
54+
credit_card_sample_data, field, region
55+
)
56+
credit_card_autofill.update_form_data(
57+
credit_card_sample_data, field, new_field_value
58+
)
5259

5360
# navigate to settings
5461
about_prefs_privacy.open()

0 commit comments

Comments
 (0)