From 5157f05996498b436d24d7b16325367e5246de25 Mon Sep 17 00:00:00 2001 From: Ignacio Date: Wed, 23 Oct 2024 13:34:32 -0600 Subject: [PATCH] Functional test now checks we can input a to-do item --- functional_tests.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/functional_tests.py b/functional_tests.py index cb08aaf..958e2af 100644 --- a/functional_tests.py +++ b/functional_tests.py @@ -1,5 +1,8 @@ import unittest +import time from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys class NewVisitorTest(unittest.TestCase): def setUp(self): @@ -12,20 +15,32 @@ class NewVisitorTest(unittest.TestCase): # Ig has heard about a cool new online to-do app. # He goes to check out its homepage self.browser.get("http://localhost:8000") + # He notices the page title and header mention to-do lists 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 - 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 # (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 # "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. # 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