Skip to content

Commit 5d8d867

Browse files
authored
Merge pull request #472 from mozilla/philimon/add-new-address
Philimon/Create test for Verify that a new Address can be added
2 parents 5d31cf1 + 2fbee81 commit 5d8d867

25 files changed

+366
-289
lines changed

l10n_CM/Unified/conftest.py

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import os
2+
from typing import List
23

34
import pytest
45

6+
from modules.browser_object_autofill_popup import AutofillPopup
7+
from modules.page_object_autofill import AddressFill, CreditCardFill
8+
from modules.page_object_prefs import AboutPrefs
9+
from modules.util import Utilities
10+
511

612
@pytest.fixture()
713
def region():
@@ -10,17 +16,47 @@ def region():
1016

1117
@pytest.fixture()
1218
def add_prefs(region: str):
13-
return [
19+
return []
20+
21+
22+
@pytest.fixture()
23+
def set_prefs(add_prefs: List[tuple[str, str | bool]], region: str):
24+
"""Set prefs"""
25+
prefs = [
1426
("extensions.formautofill.creditCards.reauth.optout", False),
1527
("extensions.formautofill.reauth.enabled", False),
1628
("browser.aboutConfig.showWarning", False),
1729
("browser.search.region", region),
1830
]
31+
prefs.extend(add_prefs)
32+
return prefs
1933

2034

2135
@pytest.fixture()
22-
def set_prefs(add_prefs: dict):
23-
"""Set prefs"""
24-
prefs = []
25-
prefs.extend(add_prefs)
26-
return prefs
36+
def address_autofill(driver):
37+
yield AddressFill(driver)
38+
39+
40+
@pytest.fixture()
41+
def autofill_popup(driver):
42+
yield AutofillPopup(driver)
43+
44+
45+
@pytest.fixture()
46+
def util():
47+
yield Utilities()
48+
49+
50+
@pytest.fixture()
51+
def about_prefs_privacy(driver):
52+
yield AboutPrefs(driver, category="privacy")
53+
54+
55+
@pytest.fixture()
56+
def about_prefs(driver):
57+
yield AboutPrefs(driver)
58+
59+
60+
@pytest.fixture()
61+
def credit_card_fill_obj(driver):
62+
yield CreditCardFill(driver)

l10n_CM/Unified/test_demo_ad_address_data_captured_in_doorhanger_and_stored.py

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from modules.browser_object_autofill_popup import AutofillPopup
55
from modules.page_object_autofill import AddressFill
66
from modules.page_object_prefs import AboutPrefs
7-
from modules.util import BrowserActions, Utilities
7+
from modules.util import Utilities
88

99

1010
@pytest.fixture()
@@ -13,41 +13,36 @@ def test_case():
1313

1414

1515
def test_demo_ad_address_data_captured_in_doorhanger_and_stored(
16-
driver: Firefox, region: str
16+
driver: Firefox,
17+
region: str,
18+
address_autofill: AddressFill,
19+
util: Utilities,
20+
autofill_popup: AutofillPopup,
21+
about_prefs_privacy: AboutPrefs,
1722
):
1823
"""
1924
C2888703 - Verify Address data are captured in the Capture Doorhanger and stored in about:preferences
2025
"""
21-
# instantiate objects
22-
address_autofill = AddressFill(driver)
23-
address_autofill_popup = AutofillPopup(driver)
24-
util = Utilities()
25-
browser_action_obj = BrowserActions(driver)
26-
2726
# create fake data and fill it in
2827
address_autofill.open()
2928
address_autofill_data = util.fake_autofill_data(region)
3029
address_autofill.save_information_basic(address_autofill_data)
3130

3231
# The "Save address?" doorhanger is displayed
33-
address_autofill_popup.element_visible("address-save-doorhanger")
32+
autofill_popup.element_visible("address-save-doorhanger")
3433

3534
# containing Street Address field
3635
expected_street_add = address_autofill_data.street_address
37-
address_autofill_popup.element_has_text(
38-
"address-doorhanger-street", expected_street_add
39-
)
36+
autofill_popup.element_has_text("address-doorhanger-street", expected_street_add)
4037

4138
# containing City field
4239
expected_city = address_autofill_data.address_level_2
43-
address_autofill_popup.element_has_text("address-doorhanger-city", expected_city)
40+
autofill_popup.element_has_text("address-doorhanger-city", expected_city)
4441

4542
expected_state = address_autofill_data.address_level_1
4643
if region not in ["FR", "DE"]:
4744
state_abbreviation = util.get_state_province_abbreviation(expected_state)
48-
address_autofill_popup.element_has_text(
49-
"address-doorhanger-state", state_abbreviation
50-
)
45+
autofill_popup.element_has_text("address-doorhanger-state", state_abbreviation)
5146

5247
# Verify Zip Code field (Different selector for DE/FR)
5348
expected_zip = address_autofill_data.postal_code
@@ -56,24 +51,21 @@ def test_demo_ad_address_data_captured_in_doorhanger_and_stored(
5651
if region in ["FR", "DE"]
5752
else "address-doorhanger-zip"
5853
)
59-
address_autofill_popup.element_has_text(zip_selector, expected_zip)
54+
autofill_popup.element_has_text(zip_selector, expected_zip)
6055

6156
# containing Country field
6257
expected_country = address_autofill_data.country
63-
address_autofill_popup.element_has_text(
64-
"address-doorhanger-country", expected_country
65-
)
58+
autofill_popup.element_has_text("address-doorhanger-country", expected_country)
6659

6760
# Click the "Save" button
68-
address_autofill_popup.click_doorhanger_button("save")
61+
autofill_popup.click_doorhanger_button("save")
6962

7063
# Navigate to about:preferences#privacy => "Autofill" section
71-
about_prefs = AboutPrefs(driver, category="privacy").open()
72-
iframe = about_prefs.get_save_addresses_popup_iframe()
73-
browser_action_obj.switch_to_iframe_context(iframe)
64+
about_prefs_privacy.open()
65+
about_prefs_privacy.switch_to_saved_addresses_popup_iframe()
7466

7567
# Verify saved addresses
76-
elements = about_prefs.get_elements("saved-addresses-values")
68+
elements = about_prefs_privacy.get_elements("saved-addresses-values")
7769

7870
# Expected values for verification
7971
expected_values = [

l10n_CM/Unified/test_demo_ad_doorhanger_shown_on_valid_address_submission.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from selenium.webdriver import Firefox
33

44
from modules.browser_object_autofill_popup import AutofillPopup
5-
from modules.page_object import AboutConfig
65
from modules.page_object_autofill import AddressFill
76
from modules.util import Utilities
87

@@ -13,25 +12,19 @@ def test_case():
1312

1413

1514
def test_address_doorhanger_displayed_after_entering_valid_address(
16-
driver: Firefox, region: str
15+
driver: Firefox,
16+
region: str,
17+
address_autofill: AddressFill,
18+
util: Utilities,
19+
autofill_popup: AutofillPopup,
1720
):
1821
"""
19-
C2886581 - Verify the Capture Doorhanger is displayed after entering valid Address data
22+
C2886581 - Verify the Capture Door hanger is displayed after entering valid Address data
2023
"""
21-
22-
# Instantiate objects
23-
address_autofill = AddressFill(driver)
24-
address_autofill_popup = AutofillPopup(driver)
25-
util = Utilities()
26-
about_config = AboutConfig(driver)
27-
28-
# Change pref value of region
29-
about_config.change_config_value("browser.search.region", region)
30-
3124
# Create fake data and fill it in
3225
address_autofill.open()
3326
address_autofill_data = util.fake_autofill_data(region)
3427
address_autofill.save_information_basic(address_autofill_data)
3528

36-
# Check "Save Address?" doorhanger appears in the Address bar
37-
address_autofill_popup.element_visible("address-save-doorhanger")
29+
# Check "Save Address?" door hanger appears in the Address bar
30+
autofill_popup.element_visible("address-save-doorhanger")

l10n_CM/Unified/test_demo_ad_email_phone_captured_in_doorhanger_and_stored.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from modules.browser_object_autofill_popup import AutofillPopup
55
from modules.page_object_autofill import AddressFill
66
from modules.page_object_prefs import AboutPrefs
7-
from modules.util import BrowserActions, Utilities
7+
from modules.util import Utilities
88

99

1010
@pytest.fixture()
@@ -13,53 +13,58 @@ def test_case():
1313

1414

1515
def test_demo_ad_email_phone_captured_in_doorhanger_and_stored(
16-
driver: Firefox, region: str
16+
driver: Firefox,
17+
region: str,
18+
address_autofill: AddressFill,
19+
util: Utilities,
20+
autofill_popup: AutofillPopup,
21+
about_prefs_privacy: AboutPrefs,
1722
):
1823
"""
1924
C2888704 - Verify tele/email data are captured in the Capture Doorhanger and stored in about:preferences
2025
"""
21-
# instantiate objects
22-
address_autofill = AddressFill(driver)
23-
address_autofill_popup = AutofillPopup(driver)
24-
util = Utilities()
25-
browser_action_obj = BrowserActions(driver)
2626

2727
# create fake data and fill it in
2828
address_autofill.open()
2929
address_autofill_data = util.fake_autofill_data(region)
3030
address_autofill.save_information_basic(address_autofill_data)
3131

3232
# The "Save address?" doorhanger is displayed
33-
address_autofill_popup.element_visible("address-save-doorhanger")
33+
autofill_popup.element_visible("address-save-doorhanger")
3434

3535
# containing email field
3636
expected_email = address_autofill_data.email
37-
address_autofill_popup.element_has_text("address-doorhanger-email", expected_email)
37+
autofill_popup.element_has_text("address-doorhanger-email", expected_email)
3838

3939
# containing phone field
4040
expected_phone = address_autofill_data.telephone
4141
with driver.context(driver.CONTEXT_CHROME):
42-
actual_phone = address_autofill_popup.get_element(
43-
"address-doorhanger-phone"
44-
).text
42+
actual_phone = autofill_popup.get_element("address-doorhanger-phone").text
4543
normalize_expected = util.normalize_phone_number(expected_phone)
4644
normalized_actual = util.normalize_phone_number(actual_phone)
4745
assert normalized_actual == normalize_expected
4846

4947
# Click the "Save" button
50-
address_autofill_popup.click_doorhanger_button("save")
48+
autofill_popup.click_doorhanger_button("save")
5149

5250
# Navigate to about:preferences#privacy => "Autofill" section
53-
about_prefs = AboutPrefs(driver, category="privacy").open()
54-
iframe = about_prefs.get_save_addresses_popup_iframe()
55-
browser_action_obj.switch_to_iframe_context(iframe)
51+
about_prefs_privacy.open()
52+
about_prefs_privacy.switch_to_saved_addresses_popup_iframe()
5653

5754
# The address saved in step 2 is listed in the "Saved addresses" modal: Email and phone
58-
elements = about_prefs.get_elements("saved-addresses-values")
59-
expected_values = [expected_phone, expected_email]
60-
found_email_phone = any(
61-
all(value in element.text for value in expected_values) for element in elements
55+
elements = map(
56+
data_sanitizer,
57+
about_prefs_privacy.get_element("saved-addresses-values").text.split(","),
6258
)
59+
expected_values = [expected_phone, expected_email]
60+
found_email_phone = list(set(elements) & set(expected_values))
6361
assert found_email_phone, (
6462
"Email or phone were not found in any of the address entries!"
6563
)
64+
65+
66+
def data_sanitizer(value: str):
67+
value = value.strip()
68+
if value[0] == "+":
69+
return value[1:]
70+
return value

l10n_CM/Unified/test_demo_ad_name_org_captured_in_doorhanger_and_stored.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
from selenium.webdriver import Firefox
33

44
from modules.browser_object_autofill_popup import AutofillPopup
5-
from modules.page_object_about_pages import AboutConfig
65
from modules.page_object_autofill import AddressFill
76
from modules.page_object_prefs import AboutPrefs
8-
from modules.util import BrowserActions, Utilities
7+
from modules.util import Utilities
98

109

1110
@pytest.fixture()
@@ -14,47 +13,41 @@ def test_case():
1413

1514

1615
def test_demo_ad_name_org_captured_in_doorhanger_and_stored(
17-
driver: Firefox, region: str
16+
driver: Firefox,
17+
region: str,
18+
address_autofill: AddressFill,
19+
util: Utilities,
20+
autofill_popup: AutofillPopup,
21+
about_prefs_privacy: AboutPrefs,
1822
):
1923
"""
2024
C2888701 - Verify name/org fields are captured in the Capture Doorhanger and stored in about:preferences
2125
"""
22-
# instantiate objects
23-
address_autofill = AddressFill(driver)
24-
address_autofill_popup = AutofillPopup(driver)
25-
util = Utilities()
26-
about_config = AboutConfig(driver)
27-
browser_action_obj = BrowserActions(driver)
28-
29-
# Change pref value of region
30-
about_config.change_config_value("browser.search.region", region)
31-
3226
# create fake data and fill it in
3327
address_autofill.open()
3428
address_autofill_data = util.fake_autofill_data(region)
3529
address_autofill.save_information_basic(address_autofill_data)
3630

3731
# The "Save address?" doorhanger is displayed
38-
address_autofill_popup.element_visible("address-save-doorhanger")
32+
autofill_popup.element_visible("address-save-doorhanger")
3933

4034
# containing name field
4135
expected_name = address_autofill_data.name
42-
address_autofill_popup.element_has_text("address-doorhanger-name", expected_name)
36+
autofill_popup.element_has_text("address-doorhanger-name", expected_name)
4337

4438
# containing org field
4539
expected_org = address_autofill_data.organization
46-
address_autofill_popup.element_has_text("address-doorhanger-org", expected_org)
40+
autofill_popup.element_has_text("address-doorhanger-org", expected_org)
4741

4842
# Click the "Save" button
49-
address_autofill_popup.click_doorhanger_button("save")
43+
autofill_popup.click_doorhanger_button("save")
5044

5145
# Navigate to about:preferences#privacy => "Autofill" section
52-
about_prefs = AboutPrefs(driver, category="privacy").open()
53-
iframe = about_prefs.get_save_addresses_popup_iframe()
54-
browser_action_obj.switch_to_iframe_context(iframe)
46+
about_prefs_privacy.open()
47+
about_prefs_privacy.switch_to_saved_addresses_popup_iframe()
5548

5649
# The address saved in step 2 is listed in the "Saved addresses" modal: name and organization
57-
elements = about_prefs.get_elements("saved-addresses-values")
50+
elements = about_prefs_privacy.get_elements("saved-addresses-values")
5851
expected_values = [expected_name, expected_org]
5952
found_name_org = any(
6053
all(value in element.text for value in expected_values) for element in elements

0 commit comments

Comments
 (0)