Spaces:
Sleeping
Sleeping
Commit ·
8ffbf47
1
Parent(s): 8266708
FT EDIT
Browse files- functional_tests.py +25 -11
functional_tests.py
CHANGED
|
@@ -12,6 +12,12 @@ class NewVisitorTest(unittest.TestCase):
|
|
| 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
|
|
@@ -23,7 +29,22 @@ class NewVisitorTest(unittest.TestCase):
|
|
| 23 |
self.assertIn("To-Do", header_text)
|
| 24 |
|
| 25 |
# She is invited to enter a to-do item straight away
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
# She enters "Use peacock feathers to make a fly"
|
| 28 |
# (Edith is very methodical)
|
| 29 |
inputbox = self.browser.find_element(By.ID, "id_new_item")
|
|
@@ -32,16 +53,9 @@ class NewVisitorTest(unittest.TestCase):
|
|
| 32 |
time.sleep(1)
|
| 33 |
|
| 34 |
# The page updates again, and now shows both items on her list
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
self.
|
| 38 |
-
"2: Use peacock feathers to make a fly",
|
| 39 |
-
[row.text for row in rows],
|
| 40 |
-
)
|
| 41 |
-
self.assertIn(
|
| 42 |
-
"1: Buy peacock feathers",
|
| 43 |
-
[row.text for row in rows],
|
| 44 |
-
)
|
| 45 |
|
| 46 |
# Satisfied, she goes back to sleep
|
| 47 |
|
|
|
|
| 12 |
def tearDown(self):
|
| 13 |
self.browser.quit()
|
| 14 |
|
| 15 |
+
# This is your new helper method
|
| 16 |
+
def check_for_row_in_list_table(self, row_text):
|
| 17 |
+
table = self.browser.find_element(By.ID, "id_list_table")
|
| 18 |
+
rows = table.find_elements(By.TAG_NAME, "tr")
|
| 19 |
+
self.assertIn(row_text, [row.text for row in rows])
|
| 20 |
+
|
| 21 |
def test_can_start_a_todo_list(self):
|
| 22 |
# Edith has heard about a cool new online to-do app.
|
| 23 |
# She goes to check out its homepage
|
|
|
|
| 29 |
self.assertIn("To-Do", header_text)
|
| 30 |
|
| 31 |
# She is invited to enter a to-do item straight away
|
| 32 |
+
inputbox = self.browser.find_element(By.ID, "id_new_item")
|
| 33 |
+
self.assertEqual(inputbox.get_attribute("placeholder"), "Enter a to-do item")
|
| 34 |
+
|
| 35 |
+
# She types "Buy peacock feathers" into a text box
|
| 36 |
+
# (Edith's hobby is tying fly-fishing lures)
|
| 37 |
+
inputbox.send_keys("Buy peacock feathers")
|
| 38 |
+
|
| 39 |
+
# When she hits enter, the page updates, and now the page lists
|
| 40 |
+
# "1: Buy peacock feathers" as an item in a to-do list table
|
| 41 |
+
inputbox.send_keys(Keys.ENTER)
|
| 42 |
+
time.sleep(1)
|
| 43 |
+
|
| 44 |
+
# HERE IS THE CHANGE: We use the helper method
|
| 45 |
+
self.check_for_row_in_list_table("1: Buy peacock feathers")
|
| 46 |
+
|
| 47 |
+
# There is still a text box inviting her to add another item.
|
| 48 |
# She enters "Use peacock feathers to make a fly"
|
| 49 |
# (Edith is very methodical)
|
| 50 |
inputbox = self.browser.find_element(By.ID, "id_new_item")
|
|
|
|
| 53 |
time.sleep(1)
|
| 54 |
|
| 55 |
# The page updates again, and now shows both items on her list
|
| 56 |
+
# HERE IS THE CHANGE: We use the helper method twice
|
| 57 |
+
self.check_for_row_in_list_table("1: Buy peacock feathers")
|
| 58 |
+
self.check_for_row_in_list_table("2: Use peacock feathers to make a fly")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
# Satisfied, she goes back to sleep
|
| 61 |
|