From 4f7cb1bb5a474cf1e5ce11efefbb0decb697984e Mon Sep 17 00:00:00 2001 From: JasonHomeWorkstationUbuntu Date: Sat, 7 Nov 2020 19:21:21 +1100 Subject: [PATCH] Finished 4.2 Using selenium to test user interactions --- src/functional_tests.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/functional_tests.py b/src/functional_tests.py index f447c63..eb76b4a 100644 --- a/src/functional_tests.py +++ b/src/functional_tests.py @@ -1,4 +1,6 @@ from selenium import webdriver +from selenium.webdriver.common.keys import Keys +import time import unittest class NewVisitorTest(unittest.TestCase): @@ -16,18 +18,33 @@ class NewVisitorTest(unittest.TestCase): # She notices the page title and header mention to-do lists self.assertIn('To-Do', self.browser.title) - self.fail('Finish the test!') + header_text = self.browser.find_element_by_tag_name('h1').text + self.assertIn('To-Do', header_text) # She is invited to enter a to-do item straight away + inputbox = self.browser.find_element_by_id('id_new_item') + self.assertEqual( + inputbox.get_attribute('placeholder'), + 'Enter a to-do item' + ) # She types "Buy peacock feathers" into a text box (Edith's hobby # is tying fly-fishing lures) + inputbox.send_keys('Buy peacock feathers') # 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) + time.sleep(1) + table = self.browser.find_element_by_id('id_list_table') + rows = table.find_element_by_tag_name('tr') + self.assertTrue( + any(row.text == '1: Buy peacock feathers' for row in rows) + ) # 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) + self.fail('Finish the test!') # The page updates again, and now shows both items on her list