refactor to NewVisitorTest() model in functional_tests, incl. new helper method for DRY table & row assertion

This commit is contained in:
Disco DeDisco
2025-12-30 23:54:44 -05:00
parent f6b73a17ea
commit 822dcd3a96

View File

@@ -5,12 +5,19 @@ import time
import unittest import unittest
class NewVisitorTest(unittest.TestCase): class NewVisitorTest(unittest.TestCase):
# Helper methods
def setUp(self): def setUp(self):
self.browser = webdriver.Firefox() self.browser = webdriver.Firefox()
def tearDown(self): def tearDown(self):
self.browser.quit() 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): def test_can_start_a_todo_list(self):
self.browser.get("http://localhost:8000") self.browser.get("http://localhost:8000")
@@ -25,20 +32,16 @@ class NewVisitorTest(unittest.TestCase):
inputbox.send_keys(Keys.ENTER) inputbox.send_keys(Keys.ENTER)
time.sleep(1) time.sleep(1)
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('1: Buy peacock feathers', [row.text for row in rows])
inputbox = self.browser.find_element(By.ID, 'id-new-item') inputbox = self.browser.find_element(By.ID, 'id-new-item')
inputbox.send_keys('Use peacock feathers to make a fly') inputbox.send_keys('Use peacock feathers to make a fly')
inputbox.send_keys(Keys.ENTER) inputbox.send_keys(Keys.ENTER)
time.sleep(1) 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__": if __name__ == "__main__":
unittest.main() unittest.main()