Skip to content

Commit ba4be21

Browse files
refactors: basic test cleanup, docstring, used conftest instansiatation
1 parent df4c0be commit ba4be21

27 files changed

+378
-306
lines changed

l10n_CM/Unified/test_demo_cc_add_new_credit_card.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_create_new_cc_profile(
2525

2626
# Go to about:preferences#privacy and open Saved Payment Methods
2727
about_prefs_privacy.open()
28-
about_prefs_privacy.switch_to_saved_payments_popup_iframe()
28+
about_prefs_privacy.open_and_switch_to_saved_payments_popup()
2929

3030
# Save CC information using fake data
3131
credit_card_sample_data = util.fake_credit_card_data(region)

l10n_CM/Unified/test_demo_cc_clear_form.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_cc_clear_form(
2727

2828
# Save a credit card in about:preferences
2929
about_prefs_privacy.open()
30-
about_prefs_privacy.switch_to_saved_payments_popup_iframe()
30+
about_prefs_privacy.open_and_switch_to_saved_payments_popup()
3131

3232
credit_card_sample_data = util.fake_credit_card_data(region)
3333
about_prefs.click_on("panel-popup-button", labels=["autofill-manage-add-button"])

l10n_CM/Unified/test_demo_cc_doorhanger_data_is_stored_in_about_prefs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_demo_cc_data_captured_in_doorhanger_and_stored(
5252

5353
# Navigate to about:preferences#privacy => "Autofill" section
5454
about_prefs_privacy.open()
55-
about_prefs_privacy.switch_to_saved_payments_popup_iframe()
55+
about_prefs_privacy.open_and_switch_to_saved_payments_popup()
5656

5757
# Get stored values
5858
elements = [

l10n_CM/Unified/test_demo_cc_dropdown_presence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_dropdown_presence_credit_card(
2626

2727
# Save a credit card in about:preferences
2828
about_prefs_privacy.open()
29-
about_prefs_privacy.switch_to_saved_payments_popup_iframe()
29+
about_prefs_privacy.open_and_switch_to_saved_payments_popup()
3030

3131
credit_card_sample_data = util.fake_credit_card_data(region)
3232
about_prefs.click_on("panel-popup-button", labels=["autofill-manage-add-button"])

l10n_CM/Unified/test_demo_cc_yellow_highlight.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_cc_yellow_highlight(
2626

2727
# Save a credit card in about:preferences
2828
about_prefs_privacy.open()
29-
about_prefs_privacy.switch_to_saved_payments_popup_iframe()
29+
about_prefs_privacy.open_and_switch_to_saved_payments_popup()
3030
credit_card_sample_data = util.fake_credit_card_data(region)
3131
about_prefs.click_on("panel-popup-button", labels=["autofill-manage-add-button"])
3232
about_prefs.fill_cc_panel_information(credit_card_sample_data)

modules/page_object_autofill.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,10 @@ def update_credit_card_information(
273273
self.update_field(field_name, field_data, autofill_popup_obj)
274274
self.click_form_button("submit")
275275

276-
if not save_card:
277-
autofill_popup_obj.click_on("update-card-info-popup-button")
278-
else:
276+
if save_card or field_name == "cc-number":
279277
autofill_popup_obj.click_on("doorhanger-save-button")
278+
else:
279+
autofill_popup_obj.click_on("update-card-info-popup-button")
280280

281281
@BasePage.context_chrome
282282
def verify_autofill_cc_data_on_hover(

modules/page_object_prefs.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,16 +268,15 @@ def get_saved_payments_popup_iframe(self) -> WebElement:
268268
"""
269269
Returns the iframe object for the dialog panel in the popup
270270
"""
271-
self.open_saved_payments_list()
271+
self.get_saved_payments_popup().click()
272272
iframe = self.get_element("browser-popup")
273273
return iframe
274274

275-
def open_saved_payments_list(self):
275+
def get_saved_payments_popup(self) -> WebElement:
276276
"""
277277
Open saved payments dialog panel
278278
"""
279-
self.get_element("prefs-button", labels=["Saved payment methods"]).click()
280-
return self
279+
return self.get_element("prefs-button", labels=["Saved payment methods"])
281280

282281
def click_edit_saved_payment(self):
283282
"""
@@ -290,12 +289,12 @@ def click_edit_saved_payment(self):
290289
edit_button.click()
291290
return self
292291

293-
def switch_to_saved_payments_popup_iframe(self) -> BasePage:
292+
def open_and_switch_to_saved_payments_popup(self) -> BasePage:
294293
"""
295-
Switch to saved payments popup frame.
294+
Open and Switch to saved payments popup frame.
296295
"""
297-
saved_payments = self.get_saved_payments_popup_iframe()
298-
self.driver.switch_to.frame(saved_payments)
296+
saved_payments_iframe = self.get_saved_payments_popup_iframe()
297+
self.driver.switch_to.frame(saved_payments_iframe)
299298
return self
300299

301300
def switch_to_edit_saved_payments_popup_iframe(self) -> BasePage:
@@ -341,6 +340,14 @@ def get_saved_addresses_popup(self) -> WebElement:
341340
"""
342341
return self.get_element("prefs-button", labels=["Saved addresses"])
343342

343+
def open_and_switch_to_saved_addresses_popup(self) -> BasePage:
344+
"""
345+
Open and Switch to saved addresses popup frame.
346+
"""
347+
saved_address_iframe = self.get_saved_addresses_popup_iframe()
348+
self.driver.switch_to.frame(saved_address_iframe)
349+
return self
350+
344351
def switch_to_saved_addresses_popup_iframe(self) -> BasePage:
345352
"""
346353
switch to save addresses popup frame.
@@ -349,6 +356,14 @@ def switch_to_saved_addresses_popup_iframe(self) -> BasePage:
349356
self.switch_to_iframe(1)
350357
return self
351358

359+
def switch_to_saved_payments_popup_iframe(self) -> BasePage:
360+
"""
361+
switch to save payments popup frame.
362+
"""
363+
self.switch_to_default_frame()
364+
self.switch_to_iframe(1)
365+
return self
366+
352367
def switch_to_edit_saved_addresses_popup_iframe(self) -> BasePage:
353368
"""
354369
Switch to form iframe to edit saved addresses.

tests/form_autofill/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
import pytest
24

35
from modules.browser_object_autofill_popup import AutofillPopup
@@ -22,6 +24,11 @@ def prefs_list(add_to_prefs_list: dict):
2224
return prefs
2325

2426

27+
@pytest.fixture()
28+
def region():
29+
return os.environ.get("FX_REGION", "US")
30+
31+
2532
@pytest.fixture()
2633
def add_to_prefs_list():
2734
return []

tests/form_autofill/test_address_autofill_attribute.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
from modules.page_object_autofill import AddressFill
66
from modules.util import Utilities
77

8-
COUNTRY_CODE = "US"
9-
108

119
@pytest.fixture()
1210
def test_case():
@@ -18,6 +16,7 @@ def test_address_attribute_selection(
1816
address_autofill: AddressFill,
1917
autofill_popup: AutofillPopup,
2018
util: Utilities,
19+
region: str,
2120
):
2221
"""
2322
C122359 - This test verifies that after filling the autofill fields and saving the data, hovering over the first
@@ -27,12 +26,13 @@ def test_address_attribute_selection(
2726
address_autofill: AddressFill instance
2827
autofill_popup: AutofillPopup instance
2928
util: Utilities instance
29+
region: country code in use
3030
"""
3131
# open the navigation page
3232
address_autofill.open()
3333

3434
# Create fake data, fill in the form, and press submit and save on the doorhanger
35-
autofill_sample_data = util.fake_autofill_data(COUNTRY_CODE)
35+
autofill_sample_data = util.fake_autofill_data(region)
3636
address_autofill.save_information_basic(autofill_sample_data)
3737
autofill_popup.click_doorhanger_button("save")
3838

tests/form_autofill/test_autofill_cc_cvv.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import json
2-
import logging
32

43
import pytest
54
from selenium.webdriver import Firefox
65

76
from modules.browser_object_autofill_popup import AutofillPopup
87
from modules.page_object_autofill import CreditCardFill
98
from modules.page_object_prefs import AboutPrefs
10-
from modules.util import BrowserActions, Utilities
9+
from modules.util import Utilities
1110

1211

1312
@pytest.fixture()
@@ -26,7 +25,7 @@ def test_autofill_cc_cvv(
2625
C122399, Test form autofill CC CVV number
2726
2827
Arguments:
29-
about_prefs_privacy: AboutPrefs instance
28+
about_prefs_privacy: AboutPrefs instance (privacy category)
3029
credit_card_autofill: CreditCardFill instance
3130
autofill_popup: AutofillPopup instance
3231
util: Utilities instance
@@ -43,7 +42,7 @@ def test_autofill_cc_cvv(
4342

4443
# navigate to prefs
4544
about_prefs_privacy.open()
46-
about_prefs_privacy.switch_to_saved_payments_popup_iframe()
45+
about_prefs_privacy.open_and_switch_to_saved_payments_popup()
4746

4847
# Get the saved CC data (first entry)
4948
cc_profile = about_prefs_privacy.get_all_saved_cc_profiles()[0]

0 commit comments

Comments
 (0)