Skip to content

Commit 5d31cf1

Browse files
authored
Merge pull request #479 from mozilla/as/cc-yellow-highlight
Anca/l10n(demo) - cc autofill yellow highlight
2 parents a950d57 + 01a86a0 commit 5d31cf1

File tree

6 files changed

+101
-2
lines changed

6 files changed

+101
-2
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 "2886601"
12+
13+
14+
def test_cc_yellow_highlight(driver: Firefox):
15+
"""
16+
C2886601 - Verify the yellow highlight appears on autofilled fields and make sure csv field is not highlighted
17+
"""
18+
19+
# Initialize objects
20+
util = Utilities()
21+
about_prefs = AboutPrefs(driver, category="privacy")
22+
about_prefs_cc_popup = AboutPrefs(driver)
23+
browser_action_obj = BrowserActions(driver)
24+
credit_card_fill_obj = CreditCardFill(driver)
25+
autofill_popup = AutofillPopup(driver)
26+
27+
# Save a credit card in about:preferences
28+
about_prefs.open()
29+
iframe = about_prefs.get_saved_payments_popup_iframe()
30+
browser_action_obj.switch_to_iframe_context(iframe)
31+
credit_card_sample_data = util.fake_credit_card_data()
32+
about_prefs_cc_popup.click_on(
33+
"panel-popup-button", labels=["autofill-manage-add-button"]
34+
)
35+
about_prefs.fill_cc_panel_information(credit_card_sample_data)
36+
37+
# Open the credit card fill form and trigger the autofill option
38+
credit_card_fill_obj.open()
39+
credit_card_fill_obj.click_on("form-field", labels=["cc-name"])
40+
autofill_popup.click_autofill_form_option()
41+
42+
# Verify that all fields have the yellow highlight, except for the cc-csv field
43+
credit_card_fill_obj.verify_field_yellow_highlights()

l10n_CM/region/CA.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"test_demo_cc_clear_form.py",
1111
"test_demo_cc_dropdown-presence.py",
1212
"test_demo_ad_autofill_name_org.py",
13+
"test_demo_cc_yellow_highlight.py",
1314
"test_demo_ad_autofill_phone_email.py"
1415
]
1516
}

l10n_CM/region/DE.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"test_demo_ad_autofill_name_org.py",
1111
"test_demo_ad_address_data_captured_in_doorhanger_and_stored.py",
1212
"test_demo_cc_clear_form.py",
13+
"test_demo_cc_yellow_highlight.py",
1314
"test_demo_ad_autofill_phone_email.py"
1415
]
1516
}

l10n_CM/region/FR.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"test_demo_ad_email_phone_captured_in_doorhanger_and_stored.py",
1212
"test_demo_cc_dropdown-presence.py",
1313
"test_demo_cc_clear_form.py",
14+
"test_demo_cc_yellow_highlight.py",
1415
"test_demo_ad_autofill_phone_email.py"
1516
]
1617
}

l10n_CM/region/US.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"test_demo_ad_email_phone_captured_in_doorhanger_and_stored.py",
1212
"test_demo_cc_dropdown-presence.py",
1313
"test_demo_cc_clear_form.py",
14+
"test_demo_cc_yellow_highlight.py",
1415
"test_demo_ad_autofill_phone_email.py"
1516
]
1617
}

modules/page_object_autofill.py

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
from typing import List
23

34
from selenium.webdriver.support import expected_conditions as EC
@@ -320,6 +321,53 @@ def verify_clear_form_all_fields(self, autofill_popup_obj: AutofillPopup):
320321
self.double_click("form-field", labels=["cc-csc"])
321322
autofill_popup_obj.ensure_autofill_dropdown_not_visible()
322323

324+
def verify_field_yellow_highlights(self, expected_highlighted_fields=None):
325+
"""
326+
Verifies that specified form fields have the expected highlight state
327+
"""
328+
if expected_highlighted_fields is None:
329+
expected_highlighted_fields = self.fields
330+
331+
browser_action_obj = BrowserActions(self.driver)
332+
333+
# Check if a color is yellow-ish
334+
def is_yellow_highlight(rgb_tuple):
335+
if len(rgb_tuple) == 3:
336+
r, g, b = rgb_tuple
337+
elif len(rgb_tuple) >= 4:
338+
r, g, b, *_ = rgb_tuple
339+
else:
340+
return False
341+
# Uses a tolerance to detect a yellow highlight
342+
return r >= 250 and g >= 250 and 180 < b < 220
343+
344+
all_fields = self.fields + ["cc-csc"]
345+
346+
for field_name in all_fields:
347+
# Bring the fields into focus
348+
self.click_on("form-field", labels=[field_name])
349+
350+
# Get the color of the fields
351+
selector = self.get_selector("form-field", labels=[field_name])
352+
colors = browser_action_obj.get_all_colors_in_element(selector)
353+
logging.info(f"Colors found in {field_name}: {colors}")
354+
355+
is_field_highlighted = any(is_yellow_highlight(color) for color in colors)
356+
should_be_highlighted = field_name in expected_highlighted_fields
357+
358+
if should_be_highlighted:
359+
assert is_field_highlighted, (
360+
f"Expected yellow highlight on {field_name}, but none found."
361+
)
362+
logging.info(f"Yellow highlight correctly found in {field_name}.")
363+
else:
364+
assert not is_field_highlighted, (
365+
f"Expected no yellow highlight on {field_name}, but found one."
366+
)
367+
logging.info(f"No yellow highlight found in {field_name}, as expected.")
368+
369+
return self
370+
323371

324372
class LoginAutofill(Autofill):
325373
"""
@@ -414,7 +462,9 @@ def send_keys_to_element(self, name: str, label: str, keys: str):
414462
elem.clear()
415463
elem.send_keys(new_value)
416464

417-
def verify_autofill_data(self, autofill_data: AutofillAddressBase, region: str, util: Utilities):
465+
def verify_autofill_data(
466+
self, autofill_data: AutofillAddressBase, region: str, util: Utilities
467+
):
418468
"""
419469
Verifies that the autofill data matches the expected values.
420470
@@ -465,7 +515,9 @@ def verify_autofill_data(self, autofill_data: AutofillAddressBase, region: str,
465515
if field == "Phone":
466516
actual = util.normalize_phone_number(actual)
467517

468-
assert actual == expected, f"Mismatch in {field}: Expected '{expected}', but got '{actual}'"
518+
assert actual == expected, (
519+
f"Mismatch in {field}: Expected '{expected}', but got '{actual}'"
520+
)
469521

470522

471523
class TextAreaFormAutofill(Autofill):

0 commit comments

Comments
 (0)