Skip to content

Commit 6a87725

Browse files
authored
Merge pull request #483 from mozilla/as/addresses-yellow-highlight
Anca/l10n demo - addresses yellow highlight on name and organization fields
2 parents c5653a0 + 1bf5e4c commit 6a87725

File tree

3 files changed

+141
-45
lines changed

3 files changed

+141
-45
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import pytest
2+
from selenium.webdriver import Firefox
3+
4+
from modules.browser_object_autofill_popup import AutofillPopup
5+
from modules.page_object_autofill import AddressFill
6+
from modules.util import Utilities
7+
8+
9+
@pytest.fixture()
10+
def test_case():
11+
return "2888559"
12+
13+
14+
def test_address_yellow_highlight_on_name_organization_fields(
15+
driver: Firefox, region: str
16+
):
17+
"""
18+
C2888559 - Verify the yellow highlight appears on autofilled fields for name and organization.
19+
"""
20+
21+
# Instantiate objects
22+
address_autofill = AddressFill(driver)
23+
address_autofill_popup = AutofillPopup(driver)
24+
util = Utilities()
25+
26+
# Create fake data and fill it in
27+
address_autofill.open()
28+
address_autofill_data = util.fake_autofill_data(region)
29+
address_autofill.save_information_basic(address_autofill_data)
30+
31+
# Click the "Save" button
32+
address_autofill_popup.click_doorhanger_button("save")
33+
34+
# Double click inside phone field and select a saved address entry from the dropdown
35+
address_autofill.double_click("form-field", labels=["name"])
36+
37+
# Click on the first element from the autocomplete dropdown
38+
first_item = address_autofill_popup.get_nth_element(1)
39+
address_autofill_popup.click_on(first_item)
40+
41+
# Verify the name and organization fields are highlighted
42+
address_autofill.verify_field_yellow_highlights(
43+
fields_to_test=["name", "organization"],
44+
expected_highlighted_fields=["name", "organization"],
45+
)

l10n_CM/region/Unified.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"test_demo_cc_doorhanger_data_is_stored_in_about_prefs.py",
1313
"test_demo_cc_doorhanger_shown_on_valid_credit_card_submission.py",
1414
"test_demo_cc_dropdown-presence.py",
15-
"test_demo_cc_yellow_highlight.py"
15+
"test_demo_cc_yellow_highlight.py",
16+
"test_demo_ad_yellow_highlight.py"
1617
]
1718
}

modules/page_object_autofill.py

Lines changed: 94 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
from typing import List
2+
from typing import List, Optional
33

44
from selenium.webdriver.support import expected_conditions as EC
55

@@ -39,6 +39,68 @@ def click_form_button(self, field_name):
3939
"""Clicks submit on the form"""
4040
self.click_on("submit-button", labels=[field_name])
4141

42+
def verify_field_highlight(
43+
self,
44+
fields_to_test: List[str],
45+
expected_highlighted_fields: Optional[List[str]] = None,
46+
extra_fields: Optional[List[str]] = None,
47+
):
48+
"""
49+
A common method to check which fields have the "yellow highlight". This is used in both CC and Address pages.
50+
- fields_to_test: The primary list of fields for this page (cc fields, address fields).
51+
- expected_highlighted_fields: Which ones are expected to be highlighted. Defaults to all in `fields_to_test`.
52+
- extra_fields: If some pages have extra fields to test (e.g. 'cc-csc'), pass them here.
53+
"""
54+
55+
if expected_highlighted_fields is None:
56+
# By default, everything in fields_to_test is expected to be highlighted
57+
expected_highlighted_fields = fields_to_test[:]
58+
59+
if extra_fields:
60+
fields_to_actually_check = fields_to_test + extra_fields
61+
else:
62+
fields_to_actually_check = fields_to_test
63+
64+
browser_action_obj = BrowserActions(self.driver)
65+
66+
def is_yellow_highlight(rgb_tuple):
67+
"""
68+
Returns True if the color tuple is bright yellow-ish.
69+
"""
70+
if len(rgb_tuple) == 3:
71+
r, g, b = rgb_tuple
72+
else:
73+
r, g, b, *_ = rgb_tuple
74+
75+
return (r >= 250) and (g >= 250) and (180 < b < 220)
76+
77+
for field_name in fields_to_actually_check:
78+
# Focus the field so the highlight is visible
79+
self.click_on("form-field", labels=[field_name])
80+
81+
# Get all colors in the field
82+
selector = self.get_selector("form-field", labels=[field_name])
83+
colors = browser_action_obj.get_all_colors_in_element(selector)
84+
logging.info(f"Colors found in '{field_name}': {colors}")
85+
86+
# Check the highlight
87+
is_field_highlighted = any(is_yellow_highlight(color) for color in colors)
88+
should_be_highlighted = field_name in expected_highlighted_fields
89+
90+
# Assert based on expectation
91+
if should_be_highlighted:
92+
assert is_field_highlighted, (
93+
f"Expected yellow highlight on '{field_name}', but none found."
94+
)
95+
logging.info(f"Yellow highlight found in '{field_name}'.")
96+
else:
97+
assert not is_field_highlighted, (
98+
f"Expected NO yellow highlight on '{field_name}', but found one."
99+
)
100+
logging.info(f"No yellow highlight in '{field_name}', as expected.")
101+
102+
return self
103+
42104

43105
class CreditCardFill(Autofill):
44106
"""
@@ -323,50 +385,15 @@ def verify_clear_form_all_fields(self, autofill_popup_obj: AutofillPopup):
323385

324386
def verify_field_yellow_highlights(self, expected_highlighted_fields=None):
325387
"""
326-
Verifies that specified form fields have the expected highlight state
388+
Reuses the common highlight-check method from the base class.
389+
We also want to include the "cc-csc" field in the test, so we
390+
pass it via 'extra_fields'.
327391
"""
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
392+
return self.verify_field_highlight(
393+
fields_to_test=self.fields,
394+
expected_highlighted_fields=expected_highlighted_fields,
395+
extra_fields=["cc-csc"],
396+
)
370397

371398

372399
class LoginAutofill(Autofill):
@@ -414,6 +441,18 @@ class AddressFill(Autofill):
414441

415442
URL_TEMPLATE = "https://mozilla.github.io/form-fill-examples/basic.html"
416443

444+
fields = [
445+
"name",
446+
"organization",
447+
"street-address",
448+
"address-level2", # city
449+
"address-level1", # state/province
450+
"postal-code",
451+
"country",
452+
"email",
453+
"tel",
454+
]
455+
417456
def save_information_basic(self, autofill_info: AutofillAddressBase):
418457
"""
419458
Saves information passed in, in the form of an AutofillAddressBase object.
@@ -519,6 +558,17 @@ def verify_autofill_data(
519558
f"Mismatch in {field}: Expected '{expected}', but got '{actual}'"
520559
)
521560

561+
def verify_field_yellow_highlights(
562+
self, fields_to_test=None, expected_highlighted_fields=None
563+
):
564+
if fields_to_test is None:
565+
fields_to_test = self.fields # By default, test all address fields
566+
567+
return self.verify_field_highlight(
568+
fields_to_test=fields_to_test,
569+
expected_highlighted_fields=expected_highlighted_fields,
570+
)
571+
522572

523573
class TextAreaFormAutofill(Autofill):
524574
"""

0 commit comments

Comments
 (0)