Skip to content

Commit 3b441f3

Browse files
committed
Yellow highlight on name/organisation field
1 parent 5d676e0 commit 3b441f3

File tree

3 files changed

+137
-45
lines changed

3 files changed

+137
-45
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 "2888569"
12+
13+
14+
def test_address_yellow_highlight_on_name_org_fields(driver: Firefox, region: str):
15+
"""
16+
C2888569 - Verify Autofill functionality when selecting an entry from the dropdown for tele/email fields
17+
"""
18+
# Instantiate objects
19+
address_autofill = AddressFill(driver)
20+
address_autofill_popup = AutofillPopup(driver)
21+
util = Utilities()
22+
23+
# Create fake data and fill it in
24+
address_autofill.open()
25+
address_autofill_data = util.fake_autofill_data(region)
26+
address_autofill.save_information_basic(address_autofill_data)
27+
28+
# Click the "Save" button
29+
address_autofill_popup.click_doorhanger_button("save")
30+
31+
# Double inside phone field and select a saved address entry from the dropdown
32+
address_autofill.double_click("form-field", labels=["name"])
33+
34+
# Click on the first element from the autocomplete dropdown
35+
first_item = address_autofill_popup.get_nth_element(1)
36+
address_autofill_popup.click_on(first_item)
37+
38+
# Verify highlighted fields
39+
address_autofill.verify_field_yellow_highlights(
40+
fields_to_test=["name", "organization"], # Only test name & org
41+
expected_highlighted_fields=["name", "organization"],
42+
)

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: 93 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,67 @@ 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_highlights_in_list(
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."
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+
if expected_highlighted_fields is None:
55+
# By default, everything in fields_to_test is expected to be highlighted
56+
expected_highlighted_fields = fields_to_test[:]
57+
58+
if extra_fields:
59+
fields_to_actually_check = fields_to_test + extra_fields
60+
else:
61+
fields_to_actually_check = fields_to_test
62+
63+
browser_action_obj = BrowserActions(self.driver)
64+
65+
def is_yellow_highlight(rgb_tuple):
66+
"""
67+
Returns True if the color tuple is bright yellow-ish.
68+
"""
69+
if len(rgb_tuple) == 3:
70+
r, g, b = rgb_tuple
71+
else:
72+
r, g, b, *_ = rgb_tuple
73+
74+
return (r >= 250) and (g >= 250) and (180 < b < 220)
75+
76+
for field_name in fields_to_actually_check:
77+
# Focus the field so the highlight is visible
78+
self.click_on("form-field", labels=[field_name])
79+
80+
# Get all colors in the field
81+
selector = self.get_selector("form-field", labels=[field_name])
82+
colors = browser_action_obj.get_all_colors_in_element(selector)
83+
logging.info(f"Colors found in '{field_name}': {colors}")
84+
85+
# Check the highlight
86+
is_field_highlighted = any(is_yellow_highlight(color) for color in colors)
87+
should_be_highlighted = field_name in expected_highlighted_fields
88+
89+
# Assert based on expectation
90+
if should_be_highlighted:
91+
assert is_field_highlighted, (
92+
f"Expected yellow highlight on '{field_name}', but none found."
93+
)
94+
logging.info(f"Yellow highlight found in '{field_name}'.")
95+
else:
96+
assert not is_field_highlighted, (
97+
f"Expected NO yellow highlight on '{field_name}', but found one."
98+
)
99+
logging.info(f"No yellow highlight in '{field_name}', as expected.")
100+
101+
return self
102+
42103

43104
class CreditCardFill(Autofill):
44105
"""
@@ -323,50 +384,15 @@ def verify_clear_form_all_fields(self, autofill_popup_obj: AutofillPopup):
323384

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

371397

372398
class LoginAutofill(Autofill):
@@ -414,6 +440,18 @@ class AddressFill(Autofill):
414440

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

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

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

523572
class TextAreaFormAutofill(Autofill):
524573
"""

0 commit comments

Comments
 (0)