Background Image
Table of Contents Table of Contents
Previous Page  327 / 478 Next Page
Information
Show Menu
Previous Page 327 / 478 Next Page
Page Background

Finishing Off Our FT, Testing Logout

We’ll extend our FT to check that the logged-in status persists, ie it’s not just something

we set in JavaScript on the client side, but the server knows about it too andwill maintain

the logged-in state if she refreshes the page. We’ll also test that she can log out.

I started off writing code a bit like this:

functional_tests/test_login.py.

# Refreshing the page, she sees it's a real session login,

# not just a one-off for that page

self

.

browser

.

refresh

()

self

.

wait_for_element_with_id

(

'id_logout'

)

navbar

=

self

.

browser

.

find_element_by_css_selector

(

'.navbar'

)

self

.

assertIn

(

'edith@mockmyid.com

'

,

navbar

.

text

)

And, after four repetitions of very similar code, a couple of helper functions suggested

themselves:

functional_tests/test_login.py (ch16l050).

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

(

'edith@mockmyid.com

'

,

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

(

'edith@mockmyid.com'

,

navbar

.

text

)

And I extended the FT like this:

functional_tests/test_login.py (ch16l049).

[

...

]

# The Persona window closes

self

.

switch_to_new_window

(

'To-Do'

)

# She can see that she is logged in

self

.

wait_to_be_logged_in

()

# Refreshing the page, she sees it's a real session login,

# not just a one-off for that page

self

.

browser

.

refresh

()

self

.

wait_to_be_logged_in

()

# Terrified of this new feature, she reflexively clicks "logout"

self

.

browser

.

find_element_by_id

(

'id_logout'

)

.

click

()

self

.

wait_to_be_logged_out

()

# The "logged out" status also persists after a refresh

self

.

browser

.

refresh

()

self

.

wait_to_be_logged_out

()

Finishing Off Our FT, Testing Logout

|

299