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

self

.

browser

.

find_element_by_tag_name

(

'button'

)

.

click

()

# The Persona window closes

self

.

switch_to_new_window

(

'To-Do'

)

# She can see that she is logged in

self

.

wait_for_element_with_id

(

'logout'

)

#

navbar

=

self

.

browser

.

find_element_by_css_selector

(

'.navbar'

)

self

.

assertIn

(

'edith@mockmyid.com

'

,

navbar

.

text

)

The FT needs a couple of helper functions, both of which do something that’s

very common in Selenium testing: they wait for something to happen. Listings

for them follow.

I found the ID of the Persona login box by opening the site manually, and using

the Firefox debug toolbar (Ctrl+Shift+I). See

Figure 15-3 .

Rather than using a “real” email address and having to click through their

authentication screens, we use a “fake” provider.

MockMyID

is one; you can also

check out

Persona Test User .

Evaluate Third-Party Systems’ Test Infrastructure

Testing should be part of how you evaluate third-party systems. When you integrate

with an external service, you’re going to have to think through how you’re going to work

with it in your functional tests.

Often you can just use the same service in your tests and in “real life”. But sometimes

you’re going to want to run against a “test” version of the third-party service. In the case

of this integration with Persona, we could have used a “real” email address; when I first

wrote this chapter, I actually had an FT that clicked through to Yahoo.com, and logged

in with a throwaway account I’d created. The problem is that it made the FT totally

reliant on particular details of Yahoo’s email login screens, which can change at any time.

Instead, MockMyID and PersonaTestUser are both linked to from the Persona docu‐

mentation, and they work very smoothly, letting us test just the important parts of the

integration.

Perhaps more critically, think about payment systems. If you start integrating payments,

they’re going to be one of the most important parts of your site, and you’re going to want

to make sure they’re tested thoroughly … but you don’t want to be putting actual trans‐

actions on real credit cards through, every time you run an FT! So most providers will

provide a “test” version of their payments API. These vary in quality (naming no names),

so make sure you investigate them thoroughly.

252

|

Chapter 15: User Authentication, Integrating Third-Party Plugins, and Mocking with JavaScript