Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
PMPL
Collection of Practice
2019
1406568923-practice
Commits
c264d8e2
Commit
c264d8e2
authored
Oct 03, 2019
by
emil farisan
Browse files
Finish Chapter 6
parent
0ea0536b
Changes
1
Hide whitespace changes
Inline
Side-by-side
functional_tests/tests.py
View file @
c264d8e2
from
django.test
import
LiveServerTestCase
from
selenium
import
webdriver
from
selenium.webdriver.common.keys
import
Keys
from
selenium.common.exceptions
import
WebDriverException
import
time
MAX_WAIT
=
10
class
NewVisitorTest
(
LiveServerTestCase
):
def
setUp
(
self
):
...
...
@@ -12,10 +15,18 @@ class NewVisitorTest(LiveServerTestCase):
def
tearDown
(
self
):
self
.
browser
.
quit
()
def
check_for_row_in_list_table
(
self
,
row_text
):
table
=
self
.
browser
.
find_element_by_id
(
'id_list_table'
)
rows
=
table
.
find_elements_by_tag_name
(
'tr'
)
self
.
assertIn
(
row_text
,
[
row
.
text
for
row
in
rows
])
def
wait_for_row_in_list_table
(
self
,
row_text
):
start_time
=
time
.
time
()
while
True
:
try
:
table
=
self
.
browser
.
find_element_by_id
(
'id_nothing'
)
rows
=
table
.
find_elements_by_tag_name
(
'tr'
)
self
.
assertIn
(
row_text
,
[
row
.
text
for
row
in
rows
])
return
except
(
AssertionError
,
WebDriverException
)
as
e
:
if
time
.
time
()
-
start_time
>
MAX_WAIT
:
raise
e
time
.
sleep
(
0.5
)
def
test_can_start_a_list_and_retrieve_it_later
(
self
):
# Edith has heard about a cool new online to-do app. She goes
...
...
@@ -41,8 +52,7 @@ class NewVisitorTest(LiveServerTestCase):
# When she hits enter, the page updates, and now the page lists
# "1: Buy peacock feathers" as an item in a to-do list
inputbox
.
send_keys
(
Keys
.
ENTER
)
time
.
sleep
(
1
)
self
.
check_for_row_in_list_table
(
'1: Buy peacock feathers'
)
self
.
wait_for_row_in_list_table
(
'1: Buy peacock feathers'
)
# There is still a text box inviting her to add another item. She
# enters "Use peacock feathers to make a fly"
...
...
@@ -50,11 +60,10 @@ class NewVisitorTest(LiveServerTestCase):
inputbox
=
self
.
browser
.
find_element_by_id
(
'id_new_item'
)
inputbox
.
send_keys
(
'Use peacock feathers to make a fly'
)
inputbox
.
send_keys
(
Keys
.
ENTER
)
time
.
sleep
(
1
)
# The page updates again, and now shows both items on her list
self
.
check
_for_row_in_list_table
(
'1: Buy peacock feathers'
)
self
.
check
_for_row_in_list_table
(
'2: Use peacock feathers to make a fly'
)
self
.
wait
_for_row_in_list_table
(
'1: Buy peacock feathers'
)
self
.
wait
_for_row_in_list_table
(
'2: Use peacock feathers to make a fly'
)
# Edith wonders whether the site will remember her list. Then she sees
# that the site has generated a unique URL for her -- there is some
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment