diff --git a/functional_tests.py b/functional_tests.py index 7d3a908..1140b42 100644 --- a/functional_tests.py +++ b/functional_tests.py @@ -5,12 +5,19 @@ import time import unittest class NewVisitorTest(unittest.TestCase): + # Helper methods def setUp(self): self.browser = webdriver.Firefox() def tearDown(self): self.browser.quit() + def check_for_row_in_list_table(self, row_text): + table = self.browser.find_element(By.ID, 'id-list-table') + rows = table.find_elements(By.TAG_NAME, 'tr') + self.assertIn(row_text, [row.text for row in rows]) + + # Test methods def test_can_start_a_todo_list(self): self.browser.get("http://localhost:8000") @@ -25,20 +32,16 @@ class NewVisitorTest(unittest.TestCase): 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.assertIn('1: Buy peacock feathers', [row.text for row in rows]) + self.check_for_row_in_list_table('1: Buy peacock feathers') inputbox = self.browser.find_element(By.ID, 'id-new-item') inputbox.send_keys('Use peacock feathers to make a fly') inputbox.send_keys(Keys.ENTER) time.sleep(1) + self.check_for_row_in_list_table('2: Use peacock feathers to make a fly') + self.check_for_row_in_list_table('1: Buy peacock feathers') - table = self.browser.find_element(By.ID, 'id-list-table') - rows = table.find_elements(By.TAG_NAME, 'tr') - self.assertIn('2: Use peacock feathers to make a fly', [row.text for row in rows]) - self.assertIn('1: Buy peacock feathers', [row.text for row in rows]) + if __name__ == "__main__": unittest.main() \ No newline at end of file