Compare commits
No commits in common. "8cdc3ec3192f3a462ffce7a20f9d50b621c3a12c" and "05b8f2194354f889dd45acf76f250d0b8cb0ae86" have entirely different histories.
8cdc3ec319
...
05b8f21943
|
@ -1,14 +1,9 @@
|
|||
from django.test import LiveServerTestCase
|
||||
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.keys import Keys
|
||||
from selenium.common.exceptions import WebDriverException
|
||||
import time
|
||||
import unittest
|
||||
|
||||
MAX_WAIT = 10
|
||||
|
||||
class NewVisitorTest(LiveServerTestCase):
|
||||
class NewVisitorTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.browser = webdriver.Firefox()
|
||||
|
@ -16,23 +11,15 @@ class NewVisitorTest(LiveServerTestCase):
|
|||
def tearDown(self):
|
||||
self.browser.quit()
|
||||
|
||||
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_list_table')
|
||||
rows = table.find_elements_by_tag_name('tr')
|
||||
self.assertIn('foo', [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 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 test_can_start_a_list_and_retrieve_it_later(self):
|
||||
# Edith has heard about a cool new online to-do app. She goes
|
||||
# to check out its homepage
|
||||
self.browser.get(self.live_server_url)
|
||||
self.browser.get('http://localhost:8000')
|
||||
|
||||
# She notices the page title and header mention to-do lists
|
||||
self.assertIn('To-Do', self.browser.title)
|
||||
|
@ -53,17 +40,19 @@ 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)
|
||||
self.wait_for_row_in_list_table('1: Buy peacock feathers')
|
||||
time.sleep(1)
|
||||
self.check_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" (Edith is very methodical)
|
||||
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.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')
|
||||
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')
|
||||
|
||||
# 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
|
||||
|
@ -71,4 +60,8 @@ class NewVisitorTest(LiveServerTestCase):
|
|||
|
||||
# She visits that URL - her to-do list is still there.
|
||||
|
||||
# Satisfied, she goes back to sleep
|
||||
# Satisfied, she goes back to sleep
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(warnings='ignore')
|
||||
|
Loading…
Reference in New Issue