It’s usually best to have a separate file for each Page object. In this case,
HomePage
and
ListPage
are so closely related it’s easier to keep them
together.
Let’s see how to use it in our test:
functional_tests/test_sharing.py (ch21l007).
from
.home_and_list_pages
import
HomePage
[
...
]
# Edith goes to the home page and starts a list
self
.
browser
=
edith_browser
list_page
=
HomePage
(
self
)
.
start_new_list
(
'Get help'
)
Let’s continue rewriting our test, using the Page object whenever we want to access
elements from the lists page:
functional_tests/test_sharing.py (ch21l008).
# She notices a "Share this list" option
share_box
=
list_page
.
get_share_box
()
self
.
assertEqual
(
share_box
.
get_attribute
(
'placeholder'
),
'your-friend@example.com')
# She shares her list.
# The page updates to say that it's shared with Oniciferous:
list_page
.
share_list_with
(
'oniciferous@example.com')
We add the following three functions to our
ListPage
:
functional_tests/home_and_list_pages.py (ch21l009).
def
get_share_box
(
self
):
return
self
.
test
.
browser
.
find_element_by_css_selector
(
'input[name=email]'
)
def
get_shared_with_list
(
self
):
return
self
.
test
.
browser
.
find_elements_by_css_selector
(
'.list-sharee'
)
def
share_list_with
(
self
,
):
self
.
get_share_box
()
.
send_keys
(
+
'
\n
'
)
self
.
test
.
wait_for
(
lambda
:
self
.
test
.
assertIn
(
,
[
item
.
text
for
item
in
self
.
get_shared_with_list
()]
))
392
|
Chapter 21: The Token Social Bit, the Page Pattern, and an Exercise for the Reader