Skip to content

Commit 5d676e0

Browse files
authored
Merge pull request #475 from mozilla/vs/CC-doorhanger-data-is-saved
Vs/cc doorhanger data is saved
2 parents a947a4d + 1eba9f8 commit 5d676e0

20 files changed

+155
-39
lines changed

SELECTOR_INFO.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,20 @@ Location: about:preferences#privacy Saved Addresses popup dialog
571571
Path to .json: modules/data/about_prefs.components.json
572572
```
573573
```
574+
Selector Name: saved-credit-cards
575+
Selector Data: "credit-cards"
576+
Description: The element that contains the saved credit cards
577+
Location: about:preferences#privacy Saved Credit Cards popup dialog
578+
Path to .json: modules/data/about_prefs.components.json
579+
```
580+
```
581+
Selector Name: saved-credit-cards-values
582+
Selector Data: "#credit-cards option"
583+
Description: The element that contains the saved credit cards values
584+
Location: about:preferences#privacy Saved Credit Cards popup dialog
585+
Path to .json: modules/data/about_prefs.components.json
586+
```
587+
```
574588
Selector Name: panel-popup-stack
575589
Selector Data: "dialogStack"
576590
Description: The element that contains the credit card profile values

l10n_CM/Unified/test_demo_ad_address_data_captured_in_doorhanger_and_stored.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,20 @@ def test_demo_ad_address_data_captured_in_doorhanger_and_stored(
2323
"""
2424
C2888703 - Verify Address data are captured in the Capture Doorhanger and stored in about:preferences
2525
"""
26-
# create fake data and fill it in
26+
# Create fake data and fill it in
2727
address_autofill.open()
2828
address_autofill_data = util.fake_autofill_data(region)
2929
address_autofill.save_information_basic(address_autofill_data)
3030

3131
# The "Save address?" doorhanger is displayed
3232
autofill_popup.element_visible("address-save-doorhanger")
3333

34-
# containing Street Address field
34+
# Containing Street Address field
3535
expected_street_add = address_autofill_data.street_address
36+
3637
autofill_popup.element_has_text("address-doorhanger-street", expected_street_add)
3738

38-
# containing City field
39+
# Containing City field
3940
expected_city = address_autofill_data.address_level_2
4041
autofill_popup.element_has_text("address-doorhanger-city", expected_city)
4142

@@ -51,10 +52,12 @@ def test_demo_ad_address_data_captured_in_doorhanger_and_stored(
5152
if region in ["FR", "DE"]
5253
else "address-doorhanger-zip"
5354
)
55+
5456
autofill_popup.element_has_text(zip_selector, expected_zip)
5557

56-
# containing Country field
58+
# Containing Country field
5759
expected_country = address_autofill_data.country
60+
5861
autofill_popup.element_has_text("address-doorhanger-country", expected_country)
5962

6063
# Click the "Save" button
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import time
2+
3+
import pytest
4+
from selenium.webdriver import Firefox
5+
6+
from modules.browser_object_autofill_popup import AutofillPopup
7+
from modules.page_object_autofill import CreditCardFill
8+
from modules.page_object_prefs import AboutPrefs
9+
from modules.util import BrowserActions, Utilities
10+
11+
12+
@pytest.fixture()
13+
def test_case():
14+
return "2886597"
15+
16+
17+
def test_demo_cc_data_captured_in_doorhanger_and_stored(driver: Firefox, region: str):
18+
"""
19+
C2889999 - Verify credit card data is captured in the Capture Doorhanger and stored in about:preferences
20+
"""
21+
22+
# Instantiate objects
23+
credit_card_fill_obj = CreditCardFill(driver)
24+
autofill_popup_obj = AutofillPopup(driver)
25+
util = Utilities()
26+
browser_action_obj = BrowserActions(driver)
27+
28+
# Navigate to page
29+
credit_card_fill_obj.open()
30+
31+
# Fill data
32+
credit_card_sample_data = util.fake_credit_card_data()
33+
credit_card_fill_obj.fill_credit_card_info(credit_card_sample_data)
34+
35+
# The "Save credit card?" doorhanger is displayed
36+
assert autofill_popup_obj.element_visible("doorhanger-save-button"), (
37+
"Credit card save doorhanger is not visible"
38+
)
39+
40+
# Verify Credit Card Doorhanger Data
41+
doorhanger_text = autofill_popup_obj.get_cc_doorhanger_data("cc-doorhanger-data")
42+
assert credit_card_sample_data.card_number[-4:] in doorhanger_text, (
43+
f"Expected last 4 digits '{credit_card_sample_data.card_number[-4:]}' but not found."
44+
)
45+
assert credit_card_sample_data.name in doorhanger_text, (
46+
f"Expected name '{credit_card_sample_data.name}' but not found."
47+
)
48+
assert credit_card_sample_data.cvv not in doorhanger_text, (
49+
f"CVV '{credit_card_sample_data.cvv}' should not be saved, but found in doorhanger."
50+
)
51+
52+
# Click the "Save" button using click_doorhanger_button
53+
autofill_popup_obj.click_doorhanger_button("save")
54+
55+
# Navigate to about:preferences#privacy => "Autofill" section
56+
about_prefs = AboutPrefs(driver, category="privacy").open()
57+
iframe = about_prefs.get_saved_payments_popup_iframe()
58+
browser_action_obj.switch_to_iframe_context(iframe)
59+
60+
# Get stored values
61+
elements = [
62+
x.strip()
63+
for x in about_prefs.get_element("saved-credit-cards-values").text.split(",")
64+
]
65+
66+
# Validate stored values match expected values
67+
assert elements[0].endswith(credit_card_sample_data.card_number[-4:]), (
68+
f"Expected last 4 digits '{credit_card_sample_data.card_number[-4:]}' but got '{elements[0]}'"
69+
)
70+
assert elements[1] == credit_card_sample_data.name, (
71+
f"Expected name '{credit_card_sample_data.name}' but got '{elements[1]}'"
72+
)
73+
assert credit_card_sample_data.cvv not in elements, (
74+
f"CVV '{credit_card_sample_data.cvv}' should not be saved, but found in stored values."
75+
)

l10n_CM/region/Unified.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
{
22
"tests": [
3-
"test_demo_cc_doorhanger_shown_on_valid_credit_card_submission.py",
4-
"test_demo_cc_add_new_credit_card.py",
3+
"test_demo_ad_address_data_captured_in_doorhanger_and_stored.py",
4+
"test_demo_ad_autofill_name_org.py",
5+
"test_demo_ad_autofill_phone_email.py",
56
"test_demo_ad_doorhanger_shown_on_valid_address_submission.py",
7+
"test_demo_ad_email_phone_captured_in_doorhanger_and_stored.py",
68
"test_demo_ad_name_org_captured_in_doorhanger_and_stored.py",
7-
"test_demo_ad_address_data_captured_in_doorhanger_and_stored.py",
8-
"test_demo_cc_dropdown-presence.py",
9+
"test_demo_ad_verify_new_address_added.py",
10+
"test_demo_cc_add_new_credit_card.py",
911
"test_demo_cc_clear_form.py",
12+
"test_demo_cc_doorhanger_data_is_stored_in_about_prefs.py",
13+
"test_demo_cc_doorhanger_shown_on_valid_credit_card_submission.py",
1014
"test_demo_cc_dropdown-presence.py",
11-
"test_demo_ad_autofill_name_org.py",
12-
"test_demo_cc_yellow_highlight.py",
13-
"test_demo_ad_autofill_phone_email.py"
15+
"test_demo_cc_yellow_highlight.py"
1416
]
1517
}

modules/browser_object_autofill_popup.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ def click_clear_form_option(self) -> BasePage:
5252
self.click_on("clear-form-option")
5353
return self
5454

55+
def get_doorhanger_cc_number(self) -> str:
56+
"""Retrieves the last 4 digits of the credit card from the doorhanger popup"""
57+
return self.get_element("doorhanger-cc-number").text
58+
59+
def get_cc_doorhanger_data(self, selector: str) -> str:
60+
"""
61+
get text for the credit card doorhanger data.
62+
"""
63+
with self.driver.context(self.driver.CONTEXT_CHROME):
64+
return self.get_element(selector).text
65+
5566
# Interaction with autocomplete list elements
5667
def get_nth_element(self, index: str) -> WebElement:
5768
"""

modules/browser_object_navigation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22

33
from selenium.common.exceptions import TimeoutException
4-
from selenium.webdriver.common.action_chains import ActionChains
4+
from selenium.webdriver import ActionChains
55
from selenium.webdriver.common.by import By
66
from selenium.webdriver.common.keys import Keys
77
from selenium.webdriver.remote.webelement import WebElement

modules/data/about_prefs.components.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@
135135
"groups": []
136136
},
137137

138+
"saved-credit-cards": {
139+
"selectorData": "credit-cards",
140+
"strategy": "id",
141+
"groups": []
142+
},
143+
144+
"saved-credit-cards-values": {
145+
"selectorData": "#credit-cards option",
146+
"strategy": "css",
147+
"groups": []
148+
},
149+
138150
"panel-popup-stack": {
139151
"selectorData": "dialogStack",
140152
"strategy": "id",

modules/data/autofill_popup.components.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@
8585
"groups": []
8686
},
8787

88+
"cc-doorhanger-data": {
89+
"selectorData": "popupnotificationcontent[class='credit-card-save-update-notification-content'] description",
90+
"strategy": "css",
91+
"groups": []
92+
},
93+
8894
"address-doorhanger-email": {
8995
"selectorData": "div.address-save-update-row-container:nth-of-type(2) div p:first-of-type span",
9096
"strategy": "css",

modules/page_base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,14 @@ def switch_to_new_window(self) -> Page:
691691
with self.driver.context(self.driver.CONTEXT_CONTENT):
692692
return self.switch_to_new_tab()
693693

694+
def switch_to_new_private_window(self) -> Page:
695+
"Switch to new private window"
696+
non_private_window = self.driver.current_window_handle
697+
original_window_idx = self.driver.window_handles.index(non_private_window)
698+
private_window = self.driver.window_handles[1 - original_window_idx]
699+
self.driver.switch_to.window(private_window)
700+
return self
701+
694702
def switch_to_frame(self, frame: str, labels=[]) -> Page:
695703
"""Switch to inline document frame"""
696704
with self.driver.context(self.driver.CONTEXT_CHROME):

0 commit comments

Comments
 (0)