Skip to content

Commit 81a8a76

Browse files
authored
Merge pull request #512 from mozilla/as/cc-hover-preview
Anca/ l10n demo - CC preview
2 parents 7b6202f + cc2334b commit 81a8a76

7 files changed

+118
-5
lines changed

SELECTOR_INFO.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,13 @@ Location: Inside chrome context, holds the data that would be showed as a previe
13681368
Path to .json: modules/data/autofill_popup.components.json
13691369
```
13701370
```
1371+
Selector Name: cc-preview-form-container
1372+
Selector Data: "credit-card-save-update-notification-content"
1373+
Description: Form container that is hidden in chrome context. Used to verify hover preview data
1374+
Location: Inside chrome context, holds the data that would be showed as a preview when autofill is hovered.
1375+
Path to .json: modules/data/autofill_popup.components.json
1376+
```
1377+
```
13711378
Selector Name: doorhanger-save-button
13721379
Selector Data: button[label='Save'].popup-notification-primary-button
13731380
Description: The "Save" button

l10n_CM/Unified/test_demo_ad_hover_name_org.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@ def test_demo_ad_hover_name_org(
3434
# Hover over each field and check data preview
3535
fields_to_test = ["name", "organization"]
3636
for field in fields_to_test:
37-
address_autofill.check_autofill_preview_for_field(field, autofill_data, autofill_popup, util)
37+
address_autofill.check_autofill_preview_for_field(
38+
field, autofill_data, autofill_popup, util
39+
)

l10n_CM/Unified/test_demo_ad_hover_over_tele_and_email_dropdown.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ def test_hover_email_and_phone_autofill_preview(
2626
autofill_popup.click_doorhanger_button("save")
2727

2828
# Check Email field preview.
29-
address_autofill.check_autofill_preview_for_field("email", autofill_data, autofill_popup, util)
29+
address_autofill.check_autofill_preview_for_field(
30+
"email", autofill_data, autofill_popup, util
31+
)
3032
# Check Phone field preview (using the correct label "tel").
31-
address_autofill.check_autofill_preview_for_field("tel", autofill_data, autofill_popup, util)
33+
address_autofill.check_autofill_preview_for_field(
34+
"tel", autofill_data, autofill_popup, util
35+
)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import pytest
2+
from selenium.webdriver import Firefox
3+
4+
from modules.browser_object_autofill_popup import AutofillPopup
5+
from modules.page_object import AboutPrefs, CreditCardFill
6+
from modules.util import BrowserActions, Utilities
7+
8+
9+
@pytest.fixture()
10+
def test_case():
11+
return "2886599"
12+
13+
14+
@pytest.fixture()
15+
def add_to_prefs_list(region: str):
16+
return [("extensions.formautofill.creditCards.supportedCountries", region)]
17+
18+
19+
def test_cc_preview(
20+
driver: Firefox,
21+
util: Utilities,
22+
about_prefs_privacy: AboutPrefs,
23+
autofill_popup: AutofillPopup,
24+
credit_card_fill_obj: CreditCardFill,
25+
):
26+
"""
27+
C2886599 - Verify that hovering over field will preview all eligible fields (except for the CVV field)
28+
"""
29+
30+
browser_action_obj = BrowserActions(driver)
31+
32+
# Save a credit card in about:preferences
33+
about_prefs_privacy.open()
34+
iframe = about_prefs_privacy.get_saved_payments_popup_iframe()
35+
browser_action_obj.switch_to_iframe_context(iframe)
36+
37+
# Generate fake CC data & add it
38+
credit_card_sample_data = util.fake_credit_card_data()
39+
about_prefs_privacy.click_on(
40+
"panel-popup-button", labels=["autofill-manage-add-button"]
41+
)
42+
about_prefs_privacy.fill_cc_panel_information(credit_card_sample_data)
43+
44+
# Open the credit card fill form
45+
credit_card_fill_obj.open()
46+
47+
# Verify the autofill preview
48+
for field in CreditCardFill.fields:
49+
credit_card_fill_obj.click_on("form-field", labels=[field])
50+
autofill_popup.ensure_autofill_dropdown_visible()
51+
autofill_popup.hover("select-form-option")
52+
credit_card_fill_obj.verify_autofill_cc_data_on_hover(
53+
credit_card_sample_data, autofill_popup
54+
)
55+
56+
credit_card_fill_obj.click_on("form-field", labels=["cc-csc"])
57+
autofill_popup.ensure_autofill_dropdown_not_visible()

l10n_CM/region/Unified.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"test_demo_ad_autofill_dropdown_present_for_email_and_phone.py",
2626
"test_demo_ad_hover_verify_address.py",
2727
"test_demo_ad_hover_over_tele_and_email_dropdown.py",
28-
"test_demo_ad_hover_name_org.py"
28+
"test_demo_ad_hover_name_org.py",
29+
"test_demo_cc_hover_verify_cc,"
2930
]
3031
}

modules/data/autofill_popup.components.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@
161161
"selectorData": "address-save-update-notification-content",
162162
"strategy": "class",
163163
"groups": []
164+
},
165+
166+
"cc-preview-form-container": {
167+
"selectorData": "credit-card-save-update-notification-content",
168+
"strategy": "class",
169+
"groups": []
164170
}
165171
}
166172

modules/page_object_autofill.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,35 @@ def update_credit_card_information(
278278
else:
279279
autofill_popup_obj.click_on("doorhanger-save-button")
280280

281+
@BasePage.context_chrome
282+
def verify_autofill_cc_data_on_hover(
283+
self,
284+
autofill_data: CreditCardBase,
285+
autofill_popup: AutofillPopup,
286+
):
287+
"""
288+
Verifies that the credit card autofill preview data matches the expected values when hovering
289+
290+
Arguments:
291+
autofill_data: CreditCardBase object containing expected credit card data.
292+
autofill_popup: AutofillPopup object to get element from dropdown.
293+
"""
294+
# Get preview data from hovering through the chrome context
295+
element = autofill_popup.get_element("cc-preview-form-container")
296+
297+
# Get every span element that is a child of the form and is not empty
298+
children = [
299+
x.get_attribute("innerHTML")
300+
for x in element.find_elements(By.TAG_NAME, "span")
301+
if len(x.get_attribute("innerHTML").strip()) >= 2
302+
]
303+
304+
for expected in children:
305+
# Check if this value exists in our CreditCardBase object
306+
assert unescape(expected) in autofill_data.__dict__.values(), (
307+
f"Mismatched data: {expected} not in {autofill_data}."
308+
)
309+
281310
@staticmethod
282311
def extract_credit_card_obj_into_list(
283312
credit_card_sample_data: CreditCardBase,
@@ -504,7 +533,14 @@ def verify_autofill_displayed(self):
504533
element = self.get_element("select-address")
505534
self.expect(EC.visibility_of(element))
506535

507-
def check_autofill_preview_for_field(self, field_label: str, autofill_data, autofill_popup, util: Utilities, region: str = None):
536+
def check_autofill_preview_for_field(
537+
self,
538+
field_label: str,
539+
autofill_data,
540+
autofill_popup,
541+
util: Utilities,
542+
region: str = None,
543+
):
508544
# Skip fields that don't appear in the dropdown for certain regions.
509545
if field_label == "address-level1" and region in ["DE", "FR"]:
510546
return

0 commit comments

Comments
 (0)