Spaces:
Sleeping
Sleeping
Commit ·
58b6f20
1
Parent(s): 02c72d1
Functional test now checks we can input a to-do item
Browse files- functional_tests.py +33 -11
functional_tests.py
CHANGED
|
@@ -1,29 +1,51 @@
|
|
| 1 |
-
import unittest
|
| 2 |
from selenium import webdriver
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
|
| 5 |
-
class NewVisitorTest(unittest.TestCase):
|
| 6 |
-
def setUp(self):
|
| 7 |
-
self.browser = webdriver.Firefox()
|
| 8 |
|
| 9 |
-
def tearDown(self):
|
| 10 |
self.browser.quit()
|
| 11 |
|
| 12 |
-
def test_can_start_a_todo_list(self):
|
| 13 |
# Edith has heard about a cool new online to-do app.
|
| 14 |
# She goes to check out its homepage
|
| 15 |
-
self.browser.get("http://localhost:8000")
|
| 16 |
|
| 17 |
# She notices the page title and header mention to-do lists
|
| 18 |
-
self.assertIn("To-Do", self.browser.title)
|
|
|
|
|
|
|
| 19 |
|
| 20 |
# She is invited to enter a to-do item straight away
|
| 21 |
-
self.
|
|
|
|
| 22 |
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
#
|
|
|
|
|
|
|
|
|
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
if __name__ == "__main__":
|
| 29 |
unittest.main()
|
|
|
|
|
|
|
| 1 |
from selenium import webdriver
|
| 2 |
+
from selenium.webdriver.common.by import By
|
| 3 |
+
from selenium.webdriver.common.keys import Keys
|
| 4 |
+
import time
|
| 5 |
+
import unittest
|
| 6 |
|
| 7 |
|
| 8 |
+
class NewVisitorTest(unittest.TestCase):
|
| 9 |
+
def setUp(self):
|
| 10 |
+
self.browser = webdriver.Firefox()
|
| 11 |
|
| 12 |
+
def tearDown(self):
|
| 13 |
self.browser.quit()
|
| 14 |
|
| 15 |
+
def test_can_start_a_todo_list(self):
|
| 16 |
# Edith has heard about a cool new online to-do app.
|
| 17 |
# She goes to check out its homepage
|
| 18 |
+
self.browser.get("http://localhost:8000")
|
| 19 |
|
| 20 |
# She notices the page title and header mention to-do lists
|
| 21 |
+
self.assertIn("To-Do", self.browser.title)
|
| 22 |
+
header_text = self.browser.find_element(By.TAG_NAME, "h1").text
|
| 23 |
+
self.assertIn("To-Do", header_text)
|
| 24 |
|
| 25 |
# She is invited to enter a to-do item straight away
|
| 26 |
+
inputbox = self.browser.find_element(By.ID, "id_new_item")
|
| 27 |
+
self.assertEqual(inputbox.get_attribute("placeholder"), "Enter a to-do item")
|
| 28 |
|
| 29 |
+
# She types "Buy peacock feathers" into a text box
|
| 30 |
+
# (Edith's hobby is tying fly-fishing lures)
|
| 31 |
+
inputbox.send_keys("Buy peacock feathers")
|
| 32 |
|
| 33 |
+
# When she hits enter, the page updates, and now the page lists
|
| 34 |
+
# "1: Buy peacock feathers" as an item in a to-do list table
|
| 35 |
+
inputbox.send_keys(Keys.ENTER)
|
| 36 |
+
time.sleep(1)
|
| 37 |
|
| 38 |
+
table = self.browser.find_element(By.ID, "id_list_table")
|
| 39 |
+
rows = table.find_elements(By.TAG_NAME, "tr")
|
| 40 |
+
self.assertTrue(any(row.text == "1: Buy peacock feathers" for row in rows))
|
| 41 |
+
|
| 42 |
+
# There is still a text box inviting her to add another item.
|
| 43 |
+
# She enters "Use peacock feathers to make a fly"
|
| 44 |
+
# (Edith is very methodical)
|
| 45 |
+
self.fail("Finish the test!")
|
| 46 |
+
|
| 47 |
+
# The page updates again, and now shows both items on her list
|
| 48 |
+
[...]
|
| 49 |
|
| 50 |
if __name__ == "__main__":
|
| 51 |
unittest.main()
|