Skip to content

Commit 328ca6a

Browse files
Philimon/hover verify (#508)
* initial way to verify hover autofill * finished adding test for hover verify * furture improvements to l10n suite and verify hover test * forgot to add selector in docs * removed useless method
1 parent 6a18302 commit 328ca6a

11 files changed

+138
-27
lines changed

SELECTOR_INFO.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,13 @@ Location: Inside any autofill-eligible form field, triggered by user interaction
13611361
Path to .json: modules/data/autofill_popup.components.json
13621362
```
13631363
```
1364+
Selector Name: address-preview-form-container
1365+
Selector Data: "address-save-update-notification-content"
1366+
Description: Form container that is hidden in chrome context. Used to verify hover preview data
1367+
Location: Inside chrome context, holds the data that would be showed as a preview when autofill is hovered.
1368+
Path to .json: modules/data/autofill_popup.components.json
1369+
```
1370+
```
13641371
Selector Name: doorhanger-save-button
13651372
Selector Data: button[label='Save'].popup-notification-primary-button
13661373
Description: The "Save" button

l10n_CM/Unified/test_demo_ad_address_data_captured_in_doorhanger_and_stored.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def test_demo_ad_address_data_captured_in_doorhanger_and_stored(
6666

6767
# Navigate to about:preferences#privacy => "Autofill" section
6868
about_prefs_privacy.open()
69+
about_prefs_privacy.get_saved_addresses_popup().click()
6970
about_prefs_privacy.switch_to_saved_addresses_popup_iframe()
7071

7172
# Verify saved addresses

l10n_CM/Unified/test_demo_ad_email_phone_captured_in_doorhanger_and_stored.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ def test_demo_ad_email_phone_captured_in_doorhanger_and_stored(
4242
if expected_phone:
4343
with driver.context(driver.CONTEXT_CHROME):
4444
actual_phone = autofill_popup.get_element("address-doorhanger-phone").text
45-
normalize_expected = util.normalize_regional_phone_numbers(
46-
expected_phone, region
47-
)
48-
normalized_actual = util.normalize_regional_phone_numbers(actual_phone, region)
45+
normalize_expected = util.normalize_phone_number(expected_phone, region)
46+
normalized_actual = util.normalize_phone_number(actual_phone, region)
4947
assert normalized_actual == normalize_expected, (
5048
f"Phone number mismatch for {region} | Expected: {normalize_expected}, Got: {normalized_actual}"
5149
)
@@ -55,6 +53,7 @@ def test_demo_ad_email_phone_captured_in_doorhanger_and_stored(
5553

5654
# Navigate to about:preferences#privacy => "Autofill" section
5755
about_prefs_privacy.open()
56+
about_prefs_privacy.get_saved_addresses_popup().click()
5857
about_prefs_privacy.switch_to_saved_addresses_popup_iframe()
5958

6059
# The address saved in step 2 is listed in the "Saved addresses" modal: Email and phone
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import logging
2+
3+
import pytest
4+
from selenium.webdriver import ActionChains, Firefox
5+
6+
from modules.browser_object_autofill_popup import AutofillPopup
7+
from modules.page_object_autofill import AddressFill
8+
from modules.page_object_prefs import AboutPrefs
9+
from modules.util import Utilities
10+
11+
12+
@pytest.fixture()
13+
def test_case():
14+
return "2888562"
15+
16+
17+
@pytest.fixture()
18+
def add_to_prefs_list(region: str):
19+
return [
20+
("extensions.formautofill.creditCards.supportedCountries", region),
21+
("extensions.formautofill.addresses.supported", "on"),
22+
]
23+
24+
25+
def test_hover_address_is_previewed(
26+
driver: Firefox,
27+
region: str,
28+
about_prefs_privacy: AboutPrefs,
29+
address_autofill: AddressFill,
30+
autofill_popup: AutofillPopup,
31+
util: Utilities,
32+
):
33+
"""
34+
C2888562: Verify that hovering over field will preview all fields
35+
"""
36+
# Create fake data and fill it in
37+
address_autofill.open()
38+
address_autofill_data = util.fake_autofill_data(region)
39+
address_autofill.save_information_basic(address_autofill_data)
40+
41+
# Click the "Save" button
42+
autofill_popup.click_doorhanger_button("save")
43+
# Hover over each field and check data preview
44+
for field in AddressFill.fields:
45+
# hack to pass over fields that don't show up in autofill dropdown
46+
if field == "address-level1" and region in ["DE", "FR"]:
47+
continue
48+
address_autofill.double_click("form-field", labels=[field])
49+
autofill_popup.ensure_autofill_dropdown_visible()
50+
autofill_popup.hover("select-form-option")
51+
address_autofill.verify_autofill_data_on_hover(
52+
address_autofill_data, autofill_popup, util
53+
)

l10n_CM/Unified/test_demo_ad_name_org_captured_in_doorhanger_and_stored.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def test_demo_ad_name_org_captured_in_doorhanger_and_stored(
4444

4545
# Navigate to about:preferences#privacy => "Autofill" section
4646
about_prefs_privacy.open()
47+
about_prefs_privacy.get_saved_addresses_popup().click()
4748
about_prefs_privacy.switch_to_saved_addresses_popup_iframe()
4849

4950
# The address saved in step 2 is listed in the "Saved addresses" modal: name and organization

l10n_CM/Unified/test_demo_ad_yellow_highlight_address.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,20 @@ def test_address_yellow_highlight_address_fields(
2121
"""
2222
C2888564 - Verify the yellow highlight appears on autofilled fields for the address fields.
2323
"""
24-
25-
# Instantiate objects
26-
address_autofill_popup = AutofillPopup(driver)
27-
2824
# Create fake data and fill it in
2925
address_autofill.open()
3026
address_autofill_data = util.fake_autofill_data(region)
3127
address_autofill.save_information_basic(address_autofill_data)
3228

3329
# Click the "Save" button
34-
address_autofill_popup.click_doorhanger_button("save")
30+
autofill_popup.click_doorhanger_button("save")
3531

3632
# Double click inside street address field and select a saved address entry from the dropdown
3733
address_autofill.double_click("form-field", labels=["street-address"])
3834

3935
# Click on the first element from the autocomplete dropdown
40-
first_item = address_autofill_popup.get_nth_element(1)
41-
address_autofill_popup.click_on(first_item)
36+
first_item = autofill_popup.get_nth_element(1)
37+
autofill_popup.click_on(first_item)
4238

4339
# Verify the address fields are highlighted
4440
address_autofill.verify_field_yellow_highlights(

l10n_CM/region/Unified.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"test_demo_ad_clear_name_org.py",
2323
"test_demo_ad_clear_address_fields.py",
2424
"test_demo_ad_clear_tel_email.py",
25-
"test_demo_ad_autofill_dropdown_present_for_email_and_phone.py"
25+
"test_demo_ad_autofill_dropdown_present_for_email_and_phone.py",
26+
"test_demo_ad_hover_verify_address.py"
2627
]
2728
}

modules/data/autofill_popup.components.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@
155155
"selectorData": "div.address-save-update-row-container:nth-of-type(1) div p:nth-of-type(5) span",
156156
"strategy": "css",
157157
"groups": []
158+
},
159+
160+
"address-preview-form-container": {
161+
"selectorData": "address-save-update-notification-content",
162+
"strategy": "class",
163+
"groups": []
158164
}
159165
}
160166

modules/page_base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,11 @@ def switch_to_default_frame(self) -> Page:
708708
self.driver.switch_to.default_content()
709709
return self
710710

711+
def switch_to_iframe(self, index: int):
712+
"""Switch to frame of given index"""
713+
self.driver.switch_to.frame(index)
714+
return self
715+
711716
def switch_to_new_tab(self) -> Page:
712717
"""Get list of all window handles, switch to the newly opened tab"""
713718
with self.driver.context(self.driver.CONTEXT_CONTENT):

modules/page_object_autofill.py

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import logging
2+
from html import unescape
23
from typing import List, Optional
34

5+
from selenium.webdriver.common.by import By
46
from selenium.webdriver.support import expected_conditions as EC
57

68
from modules.browser_object_autofill_popup import AutofillPopup
@@ -276,8 +278,9 @@ def update_credit_card_information(
276278
else:
277279
autofill_popup_obj.click_on("doorhanger-save-button")
278280

281+
@staticmethod
279282
def extract_credit_card_obj_into_list(
280-
self, credit_card_sample_data: CreditCardBase
283+
credit_card_sample_data: CreditCardBase,
281284
) -> List[str]:
282285
"""
283286
Extracts the credit card information from the object and returns it as a list.
@@ -511,15 +514,13 @@ def send_keys_to_element(self, name: str, label: str, keys: str):
511514
elem.clear()
512515
elem.send_keys(new_value)
513516

514-
def verify_autofill_data(
515-
self, autofill_data: AutofillAddressBase, region: str, util: Utilities
516-
):
517+
def verify_autofill_data(self, autofill_data: AutofillAddressBase, util: Utilities):
517518
"""
518519
Verifies that the autofill data matches the expected values.
519520
520-
:param autofill_data: AutofillAddressBase object containing expected data.
521-
:param region: The region code (e.g., "US", "DE", "FR").
522-
:param util: Utilities instance to normalize values.
521+
Arguments:
522+
autofill_data: AutofillAddressBase object containing expected data.
523+
util: Utilities instance to normalize values.
523524
"""
524525
field_mapping = {
525526
"Name": "name-field",
@@ -550,21 +551,64 @@ def verify_autofill_data(
550551
"Country": autofill_data.country_code,
551552
"Email": autofill_data.email,
552553
"Phone": util.normalize_regional_phone_numbers(
553-
autofill_data.telephone, region
554+
autofill_data.telephone, autofill_data.country_code
554555
),
555556
}
556557

558+
self.verify_data(actual_values, expected_values, util)
559+
560+
@BasePage.context_chrome
561+
def verify_autofill_data_on_hover(
562+
self,
563+
autofill_data: AutofillAddressBase,
564+
autofill_popup: AutofillPopup,
565+
util: Utilities,
566+
):
567+
"""
568+
Verifies that the autofill preview data matches the expected values when hovering
569+
570+
Arguments:
571+
autofill_data: AutofillAddressBase object containing expected data.
572+
autofill_popup: AutofillPopup object to get element from dropdown.
573+
util: Utilities instance to normalize values.
574+
"""
575+
576+
# get preview data from hovering through the chrome context
577+
element = autofill_popup.get_element("address-preview-form-container")
578+
# get every span element that is a child of the form and is not empty
579+
children = [
580+
x.get_attribute("innerHTML")
581+
for x in element.find_elements(By.TAG_NAME, "span")
582+
if len(x.get_attribute("innerHTML").strip()) >= 2
583+
]
584+
585+
# normalize phone number data
586+
autofill_data.telephone = util.normalize_regional_phone_numbers(
587+
autofill_data.telephone, autofill_data.country_code
588+
)
589+
for expected in children:
590+
if expected[0] == "+":
591+
expected = util.normalize_phone_number(expected)
592+
if len(expected) == 2 and expected != autofill_data.country_code:
593+
continue
594+
assert unescape(expected) in autofill_data.__dict__.values(), (
595+
f"Mismatched data: {expected} not in {autofill_data}."
596+
)
597+
598+
@staticmethod
599+
def verify_data(actual_values, expected_values, util: Utilities):
600+
"""Verify data between actual and expected values"""
557601
# Validate each field
558602
for field, expected in expected_values.items():
559603
actual = actual_values[field]
560604

561605
# Skip State verification for DE and FR
562-
if field == "State" and region in ["DE", "FR"]:
606+
if field == "State" and expected_values["Country"] in ["DE", "FR"]:
563607
continue
564608

565609
# Normalize phone numbers before comparison
566610
if field == "Phone":
567-
actual = util.normalize_regional_phone_numbers(actual, region)
611+
actual = util.normalize_phone_number(actual)
568612

569613
assert actual == expected, (
570614
f"Mismatch in {field}: Expected '{expected}', but got '{actual}'"
@@ -631,9 +675,7 @@ def autofill_and_verify(
631675
address_autofill_popup.click_on(first_item)
632676

633677
# Verify autofill data
634-
self.verify_autofill_data(
635-
address_autofill_data, address_autofill_data.country_code, util
636-
)
678+
self.verify_autofill_data(address_autofill_data, util)
637679

638680
# Clear form autofill
639681
self.double_click("form-field", labels=[field_label])

0 commit comments

Comments
 (0)