Skip to content

Commit 8290ceb

Browse files
sync fxa test rework
1 parent 908f5d0 commit 8290ceb

File tree

7 files changed

+148
-144
lines changed

7 files changed

+148
-144
lines changed

SELECTOR_INFO.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,6 +2056,20 @@ Location: In the FxA signin page flow
20562056
Path to .json: modules/data/fxa_home.components.json
20572057
```
20582058
```
2059+
Selector Name: signed-in-status
2060+
Selector Data: "div[role='status']"
2061+
Description: Sign in status
2062+
Location: In the FxA signin page flow
2063+
Path to .json: modules/data/fxa_home.components.json
2064+
```
2065+
```
2066+
Selector Name: manage-sync-button
2067+
Selector Data: "signup_confirmed_sync_manage_sync_button"
2068+
Description: sign up and sync confirmation
2069+
Location: In the FxA signin page flow
2070+
Path to .json: modules/data/fxa_home.components.json
2071+
```
2072+
```
20592073
Selector Name: signin-otp-input
20602074
Selector Data: "[data-testid='signin-token-code-input-field']"
20612075
Description: The FxAccount One Time Password entry field

modules/data/fxa_home.components.json

Lines changed: 89 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,91 @@
11
{
2-
"login-email-input": {
3-
"selectorData": "input[name='email']",
4-
"strategy": "css",
5-
"groups": [
6-
"requiredForPage"
7-
]
8-
9-
},
10-
11-
"submit-button": {
12-
"selectorData": "button[type='submit']",
13-
"strategy": "css",
14-
"groups": [
15-
"doNotCache"
16-
]
17-
},
18-
19-
"signup-password-input": {
20-
"selectorData": "[data-testid='new-password-input-field']",
21-
"strategy": "css",
22-
"groups": []
23-
},
24-
25-
"signup-password-repeat-input": {
26-
"selectorData": "[data-testid='verify-password-input-field']",
27-
"strategy": "css",
28-
"groups": []
29-
},
30-
31-
"age-input": {
32-
"selectorData": "[data-testid='age-input-field']",
33-
"strategy": "css",
34-
"groups": []
35-
},
36-
37-
"card-header": {
38-
"selectorData": "card-header",
39-
"strategy": "class",
40-
"groups": []
41-
},
42-
43-
"signup-otp-input": {
44-
"selectorData": "[data-testid='confirm-signup-code-input-field']",
45-
"strategy": "css",
46-
"groups": []
47-
},
48-
49-
"signin-otp-input": {
50-
"selectorData": "[data-testid='signin-token-code-input-field']",
51-
"strategy": "css",
52-
"groups": []
53-
},
54-
55-
"otp-input": {
56-
"selectorData": "input[inputmode='numeric']",
57-
"strategy": "css",
58-
"groups": []
59-
},
60-
61-
"connected-heading": {
62-
"selectorData": "fxa-connected-heading",
63-
"strategy": "id",
64-
"groups": []
65-
},
66-
67-
"continue-browsing-link": {
68-
"selectorData": "cad-not-now",
69-
"strategy": "id",
70-
"groups": []
71-
},
72-
73-
"login-password-input": {
74-
"selectorData": "input[type='password']",
75-
"strategy": "css",
76-
"groups": []
77-
},
78-
"do-it-later-button": {
79-
"selectorData": "inline_recovery_key_setup_create_do_it_later",
80-
"strategy": "id",
81-
"groups": []
82-
},
83-
"not-now-button": {
84-
"selectorData": "choice-pair-not-now",
85-
"strategy": "id",
86-
"groups": []
87-
},
88-
89-
"sign-in-button": {
90-
"selectorData": "use-logged-in",
91-
"strategy": "id",
92-
"groups": []
93-
}
2+
"login-email-input": {
3+
"selectorData": "input[name='email']",
4+
"strategy": "css",
5+
"groups": [
6+
"requiredForPage"
7+
]
8+
},
9+
"submit-button": {
10+
"selectorData": "button[type='submit']",
11+
"strategy": "css",
12+
"groups": [
13+
"doNotCache"
14+
]
15+
},
16+
"signup-password-input": {
17+
"selectorData": "[data-testid='new-password-input-field']",
18+
"strategy": "css",
19+
"groups": []
20+
},
21+
"signup-password-repeat-input": {
22+
"selectorData": "[data-testid='verify-password-input-field']",
23+
"strategy": "css",
24+
"groups": []
25+
},
26+
"age-input": {
27+
"selectorData": "[data-testid='age-input-field']",
28+
"strategy": "css",
29+
"groups": []
30+
},
31+
"card-header": {
32+
"selectorData": "card-header",
33+
"strategy": "class",
34+
"groups": []
35+
},
36+
"signup-otp-input": {
37+
"selectorData": "[data-testid='confirm-signup-code-input-field']",
38+
"strategy": "css",
39+
"groups": []
40+
},
41+
"signin-otp-input": {
42+
"selectorData": "[data-testid='signin-token-code-input-field']",
43+
"strategy": "css",
44+
"groups": []
45+
},
46+
"otp-input": {
47+
"selectorData": "input[inputmode='numeric']",
48+
"strategy": "css",
49+
"groups": []
50+
},
51+
"connected-heading": {
52+
"selectorData": "fxa-connected-heading",
53+
"strategy": "id",
54+
"groups": []
55+
},
56+
"continue-browsing-link": {
57+
"selectorData": "cad-not-now",
58+
"strategy": "id",
59+
"groups": []
60+
},
61+
"login-password-input": {
62+
"selectorData": "input[type='password']",
63+
"strategy": "css",
64+
"groups": []
65+
},
66+
"signed-in-status": {
67+
"selectorData": "div[role='status']",
68+
"strategy": "css",
69+
"groups": []
70+
},
71+
"manage-sync-button": {
72+
"selectorData": "signup_confirmed_sync_manage_sync_button",
73+
"strategy": "id",
74+
"groups": []
75+
},
76+
"do-it-later-button": {
77+
"selectorData": "inline_recovery_key_setup_create_do_it_later",
78+
"strategy": "id",
79+
"groups": []
80+
},
81+
"not-now-button": {
82+
"selectorData": "choice-pair-not-now",
83+
"strategy": "id",
84+
"groups": []
85+
},
86+
"sign-in-button": {
87+
"selectorData": "use-logged-in",
88+
"strategy": "id",
89+
"groups": []
90+
}
9491
}

modules/page_base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,11 @@ def title_contains(self, url_part: str) -> Page:
453453
self.expect(EC.title_contains(url_part))
454454
return self
455455

456+
def title_is(self, url_part: str) -> Page:
457+
"""Expect helper: wait until driver URL is given text or timeout"""
458+
self.expect(EC.title_is(url_part))
459+
return self
460+
456461
def verify_opened_image_url(self, url_substr: str, pattern: str) -> Page:
457462
"""
458463
Given a part of a URL and a regex, wait for that substring to exist in

modules/page_object_fxa_home.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from selenium.common.exceptions import NoSuchElementException, TimeoutException
2+
from selenium.webdriver.common.by import By
23
from selenium.webdriver.support import expected_conditions as EC
34

45
from modules.page_base import BasePage
@@ -19,13 +20,7 @@ def fill_password(self, password: str) -> BasePage:
1920
self.set_content_context()
2021
self.fill("login-password-input", password, press_enter=False)
2122
self.get_element("submit-button").click()
22-
# If OTP is needed, wait for the field to be ready, else move on.
23-
try:
24-
self.custom_wait(timeout=3).until(
25-
EC.presence_of_element_located(self.get_selector("connected-heading"))
26-
)
27-
except (TimeoutException, NoSuchElementException):
28-
self.element_exists("otp-input")
23+
self.element_visible("signed-in-status")
2924
return self
3025

3126
def create_new_account(self, password: str, age=30) -> BasePage:
@@ -42,7 +37,7 @@ def fill_otp_code(self, otp: str) -> BasePage:
4237
"""Given an OTP, confirm the account, submit, and wait for account activation"""
4338
self.fill("otp-input", otp, press_enter=False)
4439
self.get_element("submit-button").click()
45-
# self.element_exists("connected-heading")
40+
self.title_is("Mozilla accounts")
4641
return self
4742

4843
def finish_account_setup(self, password: str) -> BasePage:
@@ -51,6 +46,5 @@ def finish_account_setup(self, password: str) -> BasePage:
5146
self.driver.switch_to.window(self.driver.window_handles[-1])
5247
self.fill("login-password-input", password, press_enter=False)
5348
self.get_element("submit-button").click()
54-
# self.get_element("do-it-later-button").click()
55-
# self.get_element("not-now-button").click()
49+
self.element_visible("signed-in-status")
5650
return self

tests/sync_and_fxa/conftest.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44

55
import pytest
66
from fxa.core import Client
7-
from fxa.errors import OutOfProtocolError
87
from fxa.tests.utils import TestEmailAccount
98

109

11-
class FxaPrep:
12-
def __init__(self, url: str, password: str):
10+
class FxaSession:
11+
def __init__(self, url: str, password: str, restmail_session=None):
1312
self.client = Client(url)
14-
self.restmail = TestEmailAccount()
13+
self.restmail = restmail_session if restmail_session else TestEmailAccount()
1514
self.password = password
1615
self.otp_code = None
1716
logging.info(self.restmail.email)
@@ -56,29 +55,42 @@ def add_to_prefs_list():
5655

5756

5857
@pytest.fixture()
59-
def new_fxa_prep(fxa_url: str, fxa_env: str, acct_password: str) -> FxaPrep:
58+
def fxa_session(
59+
fxa_url: str, fxa_env: str, acct_password: str, fxa_test_account, request
60+
) -> FxaSession:
6061
"""Create a PyFxA object and return a dict with artifacts"""
6162
# Create a testing account using an @restmail.net address.
6263
if fxa_env == "stage":
6364
fxa_url = "https://api-accounts.stage.mozaws.net"
64-
prep = FxaPrep(fxa_url, acct_password)
65+
if fxa_test_account:
66+
prep = FxaSession(
67+
fxa_url, acct_password, request.getfixturevalue("restmail_session")
68+
)
69+
else:
70+
prep = FxaSession(fxa_url, acct_password)
6571
prep.restmail.clear()
6672
yield prep
6773
prep.destroy_account()
6874

6975

76+
@pytest.fixture()
77+
def fxa_test_account():
78+
"""return none by default"""
79+
return None
80+
81+
7082
@pytest.fixture()
7183
def restmail_session(fxa_test_account) -> TestEmailAccount:
7284
(username, _) = fxa_test_account
7385
return TestEmailAccount(email=username)
7486

7587

7688
@pytest.fixture()
77-
def create_fxa(new_fxa_prep: FxaPrep, get_otp_code) -> FxaPrep:
89+
def create_fxa(fxa_session: FxaSession, get_otp_code) -> FxaSession:
7890
"""Create FxA from a PyFxA object"""
79-
new_fxa_prep.create_account()
80-
new_fxa_prep.session.verify_email_code(get_otp_code())
81-
return new_fxa_prep
91+
fxa_session.create_account()
92+
fxa_session.session.verify_email_code(get_otp_code())
93+
return fxa_session
8294

8395

8496
@pytest.fixture()

tests/sync_and_fxa/test_existing_fxa.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytest
55
from selenium.common.exceptions import NoSuchElementException, TimeoutException
66
from selenium.webdriver import Firefox
7+
from selenium.webdriver.common.by import By
78
from selenium.webdriver.support import expected_conditions as EC
89

910
from modules.browser_object import PanelUi
@@ -25,32 +26,18 @@ def fxa_test_account():
2526
return ("[email protected]", "Test123???")
2627

2728

28-
# Attempts to deflake this have not been entirely successful
29-
@pytest.mark.skip("Revisit when PyFxA is updated")
3029
def test_sync_existing_fxa(
3130
driver: Firefox,
3231
fxa_test_account: Tuple[str, str],
3332
restmail_session,
34-
get_otp_code,
3533
screenshot,
3634
):
3735
"""C131098: User is able to log in with existing FxAccount"""
38-
(username, password) = fxa_test_account
36+
(email, password) = fxa_test_account
3937
panel_ui = PanelUi(driver)
4038
panel_ui.click_sync_sign_in_button()
4139
fxa = FxaHome(driver)
42-
fxa.sign_up_sign_in(username)
40+
fxa.sign_up_sign_in(email)
4341
fxa.fill_password(password)
44-
45-
try:
46-
fxa.custom_wait(timeout=5).until(
47-
EC.presence_of_element_located(fxa.get_selector("otp-input"))
48-
)
49-
otp = get_otp_code(restmail_session)
50-
logging.info(f"otp code: {otp}")
51-
fxa.fill_otp_code(otp)
52-
except (NoSuchElementException, TimeoutException):
53-
pass
54-
with driver.context(driver.CONTEXT_CHROME):
55-
screenshot("screenshot_test_sync_existing_fxa_chrome")
56-
panel_ui.confirm_sync_in_progress()
42+
status_element = fxa.get_element("signed-in-status").find_element(By.TAG_NAME, "p")
43+
assert "You’re signed in" in status_element.text

0 commit comments

Comments
 (0)