Functional test now checks we can input a to-do item
This commit is contained in:
parent
1e2cc408de
commit
5157f05996
@ -1,5 +1,8 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
import time
|
||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
|
from selenium.webdriver.common.by import By
|
||||||
|
from selenium.webdriver.common.keys import Keys
|
||||||
|
|
||||||
class NewVisitorTest(unittest.TestCase):
|
class NewVisitorTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -12,20 +15,32 @@ class NewVisitorTest(unittest.TestCase):
|
|||||||
# Ig has heard about a cool new online to-do app.
|
# Ig has heard about a cool new online to-do app.
|
||||||
# He goes to check out its homepage
|
# He goes to check out its homepage
|
||||||
self.browser.get("http://localhost:8000")
|
self.browser.get("http://localhost:8000")
|
||||||
|
|
||||||
# He notices the page title and header mention to-do lists
|
# He notices the page title and header mention to-do lists
|
||||||
self.assertIn("To-Do", self.browser.title)
|
self.assertIn("To-Do", self.browser.title)
|
||||||
|
header_text = self.browser.find_element(By.TAG_NAME, "h1").text
|
||||||
|
self.assertIn("To-Do", header_text)
|
||||||
|
|
||||||
# He is invited to enter a to-do item straight away
|
# He is invited to enter a to-do item straight away
|
||||||
self.fail("Finish the test!")
|
inputbox = self.browser.find_element(By.ID, "id_new_item")
|
||||||
|
self.assertEqual(inputbox.get_attribute("placeholder"), "Enter a to-do item")
|
||||||
|
|
||||||
# He types "Buy peacock feathers" into a text box
|
# He types "Buy peacock feathers" into a text box
|
||||||
# (Ig's hobby is tying fly-fishing lures)
|
# (Ig's hobby is tying fly-fishing lures)
|
||||||
|
inputbox.send_keys("Buy peacock feathers")
|
||||||
|
|
||||||
# When he hits enter, the page updates, and now the page lists
|
# When he hits enter, the page updates, and now the page lists
|
||||||
# "1: Buy peacock feathers" as an item in a to-do list
|
# "1: Buy peacock feathers" as an item in a to-do list
|
||||||
|
inputbox.send_keys(Keys.ENTER)
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
table = self.browser.find_element(By.ID, "id_list_table")
|
||||||
|
rows = table.find_elements(By.TAG_NAME, "tr")
|
||||||
|
self.assertTrue(any(row.text == "1: Buy peacock feathers" for row in rows))
|
||||||
|
|
||||||
# There is still a text box inviting him to add another item.
|
# There is still a text box inviting him to add another item.
|
||||||
# He enters "Use peacock feathers to make a fly" (Ig is very methodical)
|
# He enters "Use peacock feathers to make a fly" (Ig is very methodical)
|
||||||
|
self.fail("Finish the test!")
|
||||||
|
|
||||||
# The page updates again, and now shows both items on his list
|
# The page updates again, and now shows both items on his list
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user