![Show Menu](styles/mobile-menu.png)
![Page Background](./../common/page-substrates/page0333.png)
Checking It Works
To check it works, it would be good to use the
wait_to_be_logged_in
function we
defined in our last test. To access it from a different test, we’ll need to pull it up into
FunctionalTest
, as well as a couple of other methods. We’ll also tweak them slightly so
that they can take an arbitrary email address as a parameter:
functional_tests/base.py (ch17l002-2).
from
selenium.webdriver.support.ui
import
WebDriverWait
[
...
]
class
FunctionalTest
(
StaticLiveServerCase
):
[
...
]
def
wait_for_element_with_id
(
self
,
element_id
):
[
...
]
def
wait_to_be_logged_in
(
self
,
):
self
.
wait_for_element_with_id
(
'id_logout'
)
navbar
=
self
.
browser
.
find_element_by_css_selector
(
'.navbar'
)
self
.
assertIn
(
,
navbar
.
text
)
def
wait_to_be_logged_out
(
self
,
):
self
.
wait_for_element_with_id
(
'id_login'
)
navbar
=
self
.
browser
.
find_element_by_css_selector
(
'.navbar'
)
self
.
assertNotIn
(
,
navbar
.
text
)
That means a small tweak in
test_login.py
:
functional_tests/test_login.py (ch17l003).
TEST_EMAIL
=
'edith@mockmyid.com'
[
...
]
def
test_login_with_persona
(
self
):
[
...
]
self
.
browser
.
find_element_by_id
(
'authentication_email'
)
.
send_keys
(
TEST_EMAIL
)
self
.
browser
.
find_element_by_tag_name
(
'button'
)
.
click
()
[
...
]
# She can see that she is logged in
self
.
wait_to_be_logged_in
(
=
TEST_EMAIL
)
[
...
]
self
.
wait_to_be_logged_in
(
=
TEST_EMAIL
)
[
...
]
self
.
wait_to_be_logged_out
(
=
TEST_EMAIL
)
[
...
]
self
.
wait_to_be_logged_out
(
=
TEST_EMAIL
)
Skipping the Login Process by Pre-creating a Session
|
305