Skip to content

Commit 9e7f76f

Browse files
Merge pull request #558 from mozilla/philimon/live-poc
Philimon/live poc
2 parents bbdc044 + fa76477 commit 9e7f76f

File tree

73 files changed

+1429
-676
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1429
-676
lines changed

SELECTOR_INFO.md

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -571,13 +571,6 @@ Location: about:preferences#privacy popup dialog
571571
Path to .json: modules/data/about_prefs.components.json
572572
```
573573
```
574-
Selector Name: dialog-close-button
575-
Selector Data: "dialogClose"
576-
Description: The close button of the popup dialog
577-
Location: top right corner of about:preferences popup dialog
578-
Path to .json: modules/data/about_prefs.components.json
579-
```
580-
```
581574
Selector Name: saved-addresses
582575
Selector Data: "addresses"
583576
Description: The element that contains the saved addresses
@@ -1368,14 +1361,7 @@ Location: Inside any autofill-eligible form field, triggered by user interaction
13681361
Path to .json: modules/data/autofill_popup.components.json
13691362
```
13701363
```
1371-
Selector Name: address-preview-form-container
1372-
Selector Data: "address-save-update-notification-content"
1373-
Description: Form container that is hidden in chrome context. Used to verify hover preview data
1374-
Location: Inside chrome context, holds the data that would be showed as a preview when autofill is hovered.
1375-
Path to .json: modules/data/autofill_popup.components.json
1376-
```
1377-
```
1378-
Selector Name: cc-preview-form-container
1364+
Selector Name: preview-form-container
13791365
Selector Data: ".autocomplete-richlistbox richlistitem"
13801366
Description: Form container that is hidden in chrome context. Used to verify hover preview data
13811367
Location: Inside chrome context, holds the data that would be showed as a preview when autofill is hovered.

l10n_CM/Unified/conftest.py

Lines changed: 210 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
import errno
2+
import logging
13
import os
4+
import socket
5+
from json import load
26
from typing import List
37

48
import pytest
@@ -8,12 +12,44 @@
812
from modules.page_object_prefs import AboutPrefs
913
from modules.util import Utilities
1014

15+
current_dir = os.path.dirname(__file__)
16+
parent_dir = os.path.dirname(current_dir)
17+
18+
LOCALHOST = "127.0.0.1"
19+
PORT = 8080
20+
21+
22+
def is_port_in_use() -> bool:
23+
"""Check if the port is already open (server running)."""
24+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
25+
return s.connect_ex((LOCALHOST, PORT)) == 0
26+
27+
28+
def get_html_files(live_site, region):
29+
address_path_to_site = (
30+
parent_dir + f"/sites/{live_site}/{region}/{live_site}_ad.html"
31+
)
32+
cc_path_to_site = parent_dir + f"/sites/{live_site}/{region}/{live_site}_cc.html"
33+
address_html_file, cc_html_file = "", ""
34+
if os.path.exists(address_path_to_site) and os.path.exists(cc_path_to_site):
35+
with open(address_path_to_site, "r", encoding="utf-8") as fp:
36+
address_html_file = fp.read()
37+
with open(cc_path_to_site, "r", encoding="utf-8") as fp:
38+
cc_html_file = fp.read()
39+
return address_html_file, cc_html_file
40+
return address_html_file, cc_html_file
41+
1142

1243
@pytest.fixture()
1344
def region():
1445
return os.environ.get("FX_REGION", "US")
1546

1647

48+
@pytest.fixture()
49+
def live_site():
50+
return os.environ.get("CM_SITE", "demo")
51+
52+
1753
@pytest.fixture()
1854
def add_to_prefs_list(region: str):
1955
return []
@@ -33,30 +69,196 @@ def prefs_list(add_to_prefs_list: List[tuple[str, str | bool]], region: str):
3369

3470

3571
@pytest.fixture()
36-
def address_autofill(driver):
37-
yield AddressFill(driver)
72+
def ad_site_data(live_site, region):
73+
ad_live_site = (
74+
f"{live_site}/{region}/{live_site}_ad"
75+
if live_site != "demo"
76+
else f"{live_site}/{live_site}_ad"
77+
)
78+
path_to_site = parent_dir + "/constants/"
79+
with open(path_to_site + ad_live_site + ".json", "r") as fp:
80+
live_site_data = load(fp)
81+
# Remove address level 1 for regions other than US and CA
82+
if region not in {"US", "CA"} and live_site_data["field_mapping"].get(
83+
"address_level_1"
84+
):
85+
live_site_data["fields"].remove(
86+
live_site_data["field_mapping"]["address_level_1"]
87+
)
88+
del live_site_data["field_mapping"]["address_level_1"]
89+
return live_site_data
90+
91+
92+
@pytest.fixture()
93+
def cc_site_data(live_site, region):
94+
cc_live_site = (
95+
f"{live_site}/{region}/{live_site}_cc"
96+
if live_site != "demo"
97+
else f"{live_site}/{live_site}_cc"
98+
)
99+
path_to_site = parent_dir + "/constants/"
100+
with open(path_to_site + cc_live_site + ".json", "r") as fp:
101+
live_site_data = load(fp)
102+
return live_site_data
103+
104+
105+
@pytest.fixture
106+
def is_live_site(live_site):
107+
"""Determine if the site is live."""
108+
return live_site != "demo"
109+
110+
111+
@pytest.fixture(scope="session")
112+
def httpserver_listen_address():
113+
"""Set port for local http server"""
114+
return LOCALHOST, PORT
115+
116+
117+
@pytest.fixture()
118+
def serve_live_site(is_live_site, live_site, region, request):
119+
"""Serve the live site only if needed."""
120+
if not is_live_site or is_port_in_use():
121+
return
122+
# only serve content if url is already not served.
123+
try:
124+
ad_html_file, cc_html_file = get_html_files(live_site, region)
125+
http_server = request.getfixturevalue("httpserver")
126+
http_server.expect_request(f"/{live_site}_ad.html").respond_with_data(
127+
ad_html_file, content_type="text/html"
128+
)
129+
http_server.expect_request(f"/{live_site}_cc.html").respond_with_data(
130+
cc_html_file, content_type="text/html"
131+
)
132+
except OSError as e:
133+
if e == errno.EADDRINUSE:
134+
logging.info(f"{live_site} already served.")
135+
finally:
136+
return
137+
138+
139+
@pytest.fixture()
140+
def ad_form_field(ad_site_data):
141+
selector = ad_site_data.get("form_field")
142+
return (
143+
{"form-field": {"selectorData": selector, "strategy": "css", "groups": []}}
144+
if selector
145+
else {}
146+
)
147+
148+
149+
@pytest.fixture()
150+
def cc_form_field(cc_site_data):
151+
selector = cc_site_data.get("form_field")
152+
return (
153+
{"form-field": {"selectorData": selector, "strategy": "css", "groups": []}}
154+
if selector
155+
else {}
156+
)
157+
158+
159+
@pytest.fixture()
160+
def address_autofill(driver, ad_site_data, ad_form_field, serve_live_site):
161+
af = AddressFill(
162+
driver,
163+
url_template=ad_site_data.get("url"),
164+
field_mapping=ad_site_data.get("field_mapping"),
165+
fields=ad_site_data.get("fields"),
166+
)
167+
af.elements |= ad_form_field
168+
return af
169+
170+
171+
@pytest.fixture()
172+
def credit_card_autofill(driver, cc_site_data, cc_form_field, serve_live_site):
173+
cf = CreditCardFill(
174+
driver,
175+
url_template=cc_site_data.get("url"),
176+
field_mapping=cc_site_data.get("field_mapping"),
177+
fields=cc_site_data.get("fields"),
178+
)
179+
cf.elements |= cc_form_field
180+
return cf
38181

39182

40183
@pytest.fixture()
41184
def autofill_popup(driver):
42-
yield AutofillPopup(driver)
185+
return AutofillPopup(driver)
43186

44187

45188
@pytest.fixture()
46189
def util():
47-
yield Utilities()
190+
return Utilities()
48191

49192

50193
@pytest.fixture()
51194
def about_prefs_privacy(driver):
52-
yield AboutPrefs(driver, category="privacy")
195+
return AboutPrefs(driver, category="privacy")
53196

54197

55198
@pytest.fixture()
56199
def about_prefs(driver):
57-
yield AboutPrefs(driver)
200+
return AboutPrefs(driver)
201+
202+
203+
@pytest.fixture()
204+
def populate_saved_payments(
205+
about_prefs_privacy: AboutPrefs, util: Utilities, region: str
206+
):
207+
"""Fixture to add cc data through saved payments method."""
208+
# Go to about:preferences#privacy and open Saved Payment Methods
209+
about_prefs_privacy.open()
210+
about_prefs_privacy.open_and_switch_to_saved_payments_popup()
211+
212+
# Save CC information using fake data
213+
credit_card_sample_data = util.fake_credit_card_data(region)
214+
215+
# Add a new CC profile
216+
about_prefs_privacy.click_add_on_dialog_element()
217+
about_prefs_privacy.add_entry_to_saved_payments(credit_card_sample_data)
218+
return credit_card_sample_data
219+
220+
221+
@pytest.fixture()
222+
def populate_saved_addresses(
223+
about_prefs_privacy: AboutPrefs, util: Utilities, region: str
224+
):
225+
"""Fixture to add cc data through saved payments method."""
226+
# Go to about:preferences#privacy and open Saved Addresses Methods
227+
about_prefs_privacy.open()
228+
about_prefs_privacy.open_and_switch_to_saved_addresses_popup()
229+
230+
# Save address information using fake data
231+
address_data_sample_data = util.fake_autofill_data(region)
232+
233+
# Add a new address profile
234+
about_prefs_privacy.click_add_on_dialog_element()
235+
about_prefs_privacy.add_entry_to_saved_addresses(address_data_sample_data)
236+
return address_data_sample_data
237+
238+
239+
@pytest.fixture()
240+
def fill_and_save_address(
241+
address_autofill: AddressFill, ad_site_data, region: str, request
242+
):
243+
"""
244+
Fixture to populate address entry depending on whether the url is a live site.
245+
If live site, populate data through about:prefs, if not fill directly through page.
246+
"""
247+
if ad_site_data.get("url"):
248+
return request.getfixturevalue("populate_saved_addresses")
249+
address_autofill.open()
250+
return address_autofill.fill_and_save(region)
58251

59252

60253
@pytest.fixture()
61-
def credit_card_autofill(driver):
62-
yield CreditCardFill(driver)
254+
def fill_and_save_payments(
255+
credit_card_autofill: CreditCardFill, cc_site_data, region: str, request
256+
):
257+
"""
258+
Fixture to populate cc entry depending on whether the url is a live site.
259+
If live site, populate data through about:prefs, if not fill directly through page.
260+
"""
261+
if cc_site_data.get("url"):
262+
return request.getfixturevalue("populate_saved_payments")
263+
credit_card_autofill.open()
264+
return credit_card_autofill.fill_and_save(region)

l10n_CM/Unified/test_demo_ad_0_add_new_address.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44
from selenium.webdriver import Firefox
55

6+
from modules.classes.autofill_base import AutofillAddressBase
67
from modules.page_object_prefs import AboutPrefs
78
from modules.util import Utilities
89

@@ -21,23 +22,21 @@ def add_to_prefs_list(region: str):
2122

2223

2324
def test_verify_new_address_is_added(
24-
driver: Firefox, region: str, about_prefs_privacy: AboutPrefs, util: Utilities
25+
driver: Firefox,
26+
region: str,
27+
about_prefs_privacy: AboutPrefs,
28+
util: Utilities,
29+
populate_saved_addresses: AutofillAddressBase,
2530
):
2631
"""
2732
C2886580: Verify that a new Address can be added
2833
"""
2934
# invert state_province_abbr to help with verification
3035
inverted_state_province_abbr = {v: k for k, v in util.state_province_abbr.items()}
31-
# generate fake data for region
32-
address_autofill_data = util.fake_autofill_data(region)
3336

34-
# open saved addresses
35-
about_prefs_privacy.open()
37+
# address autofill data
38+
address_autofill_data = populate_saved_addresses
3639
about_prefs_privacy.open_and_switch_to_saved_addresses_popup()
37-
# add new entry to saved addresses
38-
about_prefs_privacy.click_add_on_dialog_element()
39-
about_prefs_privacy.add_entry_to_saved_addresses(address_autofill_data)
40-
about_prefs_privacy.switch_to_saved_addresses_popup_iframe()
4140

4241
# verify that the address saved is the same.
4342
# The address saved in step 2 is listed in the "Saved addresses" modal: name and organization

l10n_CM/Unified/test_demo_ad_1a_dropdown_name_org_fields.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import pytest
22
from selenium.webdriver import Firefox
33

4-
from modules.browser_object_autofill_popup import AutofillPopup
4+
from modules.classes.autofill_base import AutofillAddressBase
55
from modules.page_object_autofill import AddressFill
6-
from modules.util import Utilities
76

87

98
@pytest.fixture()
@@ -15,20 +14,20 @@ def test_dropdown_presence_name_organization(
1514
driver: Firefox,
1615
region: str,
1716
address_autofill: AddressFill,
18-
util: Utilities,
19-
autofill_popup: AutofillPopup,
17+
fill_and_save_address: AutofillAddressBase,
2018
):
2119
"""
2220
C2888556 - Verify that the autofill dropdown is displayed for the name and organization fields after an address was
2321
previously saved
2422
"""
25-
26-
# Create fake data and fill it in
23+
# open address filling url page
2724
address_autofill.open()
28-
address_autofill.fill_and_save(region)
25+
26+
# scroll to first form field
27+
address_autofill.scroll_to_form_field()
2928

3029
# Verify that the name and organization fields have the autofill dropdown present
31-
fields_to_test = ["name", "organization"]
30+
fields_to_test = ["name", "given_name", "family_name", "organization"]
3231

3332
address_autofill.verify_field_autofill_dropdown(
3433
region=region, fields_to_test=fields_to_test

0 commit comments

Comments
 (0)