Skip to content

Commit e5d4b1b

Browse files
Merge pull request #548 from mozilla/philimon/fix_preview_issue
[Philimon] Fix for preview cc tests.
2 parents c4f4cb9 + 34579ae commit e5d4b1b

File tree

4 files changed

+74
-27
lines changed

4 files changed

+74
-27
lines changed

SELECTOR_INFO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@ Path to .json: modules/data/autofill_popup.components.json
13761376
```
13771377
```
13781378
Selector Name: cc-preview-form-container
1379-
Selector Data: "credit-card-save-update-notification-content"
1379+
Selector Data: ".autocomplete-richlistbox richlistitem"
13801380
Description: Form container that is hidden in chrome context. Used to verify hover preview data
13811381
Location: Inside chrome context, holds the data that would be showed as a preview when autofill is hovered.
13821382
Path to .json: modules/data/autofill_popup.components.json

l10n_CM/Unified/test_demo_cc_2_preview.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,11 @@ def test_cc_preview(
4242
# Open credit card form page
4343
credit_card_fill_obj.open()
4444

45-
# Verify the autofill preview
46-
for field in CreditCardFill.fields:
47-
credit_card_fill_obj.click_on("form-field", labels=[field])
48-
autofill_popup.ensure_autofill_dropdown_visible()
49-
autofill_popup.hover("select-form-option")
50-
credit_card_fill_obj.verify_autofill_cc_data_on_hover(
51-
credit_card_sample_data, autofill_popup
45+
# Hover over each field and check data preview
46+
fields_to_test = ["cc-name", "cc-number", "cc-exp-month", "cc-exp-year"]
47+
for field in fields_to_test:
48+
credit_card_fill_obj.check_cc_autofill_preview_for_field(
49+
field, credit_card_sample_data, autofill_popup
5250
)
5351

5452
credit_card_fill_obj.click_on("form-field", labels=["cc-csc"])

modules/data/autofill_popup.components.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,10 @@
164164
"strategy": "class",
165165
"groups": []
166166
},
167-
168-
"cc-preview-form-container": {
169-
"selectorData": "credit-card-save-update-notification-content",
170-
"strategy": "class",
171-
"groups": []
167+
"cc-preview-form-container": {
168+
"selectorData": ".autocomplete-richlistbox richlistitem",
169+
"strategy": "css",
170+
"groups": []
172171
}
173172
}
174173

modules/page_object_autofill.py

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import logging
23
from html import unescape
34
from typing import List, Optional
@@ -295,20 +296,40 @@ def verify_autofill_cc_data_on_hover(
295296
autofill_popup: AutofillPopup object to get element from dropdown.
296297
"""
297298
# Get preview data from hovering through the chrome context
298-
element = autofill_popup.get_element("cc-preview-form-container")
299+
try:
300+
# Attempt to parse the string as JSON
301+
container = json.loads(
302+
autofill_popup.get_element("cc-preview-form-container").get_attribute(
303+
"ac-comment"
304+
)
305+
)
306+
except json.JSONDecodeError:
307+
# If parsing fails, raise ValueError.
308+
raise ValueError("Given preview data is incomplete.")
309+
container_data = container.get("fillMessageData", {}).get("profile", {})
310+
assert container_data, "No preview data available."
311+
assert all(field in container_data.keys() for field in self.fields), (
312+
"Not all fields present in preview data."
313+
)
299314

300-
# Get every span element that is a child of the form and is not empty
301-
children = [
302-
x.get_attribute("innerHTML")
303-
for x in element.find_elements(By.TAG_NAME, "span")
304-
if len(x.get_attribute("innerHTML").strip()) >= 2
315+
# sanitize data
316+
autofill_data.card_number = autofill_data.card_number[-4:]
317+
expected_values = [
318+
int(val) if val.isnumeric() else val
319+
for val in autofill_data.__dict__.values()
305320
]
306-
307-
for expected in children:
308-
# Check if this value exists in our CreditCardBase object
309-
assert unescape(expected) in autofill_data.__dict__.values(), (
310-
f"Mismatched data: {expected} not in {autofill_data}."
311-
)
321+
for field, value in container_data.items():
322+
if field in self.fields:
323+
value = str(value)
324+
if field == "cc-number":
325+
value = value[-4:]
326+
elif field == "cc-exp-year":
327+
value = value[-2:]
328+
value = int(value) if value.isnumeric() else value
329+
# Check if this value exists in our CreditCardBase object
330+
assert value in expected_values, (
331+
f"Mismatched data: {(field, value)} not in {expected_values}."
332+
)
312333

313334
@staticmethod
314335
def extract_credit_card_obj_into_list(
@@ -367,6 +388,25 @@ def verify_updated_information(
367388
self.verify_credit_card_form_data(credit_card_sample_data)
368389
return self
369390

391+
def check_cc_autofill_preview_for_field(
392+
self,
393+
field_label: str,
394+
credit_card_sample_data: CreditCardBase,
395+
autofill_popup: AutofillPopup,
396+
):
397+
"""
398+
Check that hovering over a field autofill option will prefill the other fields.
399+
400+
Arguments:
401+
field_label: str,
402+
credit_card_sample_data: credit card autofill sample data,
403+
autofill_popup: AutofillPopup instance
404+
"""
405+
self.double_click("form-field", labels=[field_label])
406+
autofill_popup.ensure_autofill_dropdown_visible()
407+
autofill_popup.hover("select-form-option")
408+
self.verify_autofill_cc_data_on_hover(credit_card_sample_data, autofill_popup)
409+
370410
def update_cc(
371411
self,
372412
util: Utilities,
@@ -539,18 +579,28 @@ def verify_autofill_displayed(self):
539579
def check_autofill_preview_for_field(
540580
self,
541581
field_label: str,
542-
autofill_data,
582+
address_sample_data,
543583
autofill_popup,
544584
util: Utilities,
545585
region: str = None,
546586
):
587+
"""
588+
Check that hovering over a field autofill option will prefill the other fields.
589+
590+
Arguments:
591+
field_label: str,
592+
address_sample_data: address autofill sample data,
593+
autofill_popup: AutofillPopup instance
594+
util: Utilities instance
595+
region: country code in use
596+
"""
547597
# Skip fields that don't appear in the dropdown for certain regions.
548598
if field_label == "address-level1" and region in ["DE", "FR"]:
549599
return
550600
self.double_click("form-field", labels=[field_label])
551601
autofill_popup.ensure_autofill_dropdown_visible()
552602
autofill_popup.hover("select-form-option")
553-
self.verify_autofill_data_on_hover(autofill_data, autofill_popup, util)
603+
self.verify_autofill_data_on_hover(address_sample_data, autofill_popup, util)
554604

555605
def send_keys_to_element(self, name: str, label: str, keys: str):
556606
"""

0 commit comments

Comments
 (0)