5.4 Three Strikes and Refactor

chap5
Jason Zhu 2020-11-08 20:50:27 +11:00
parent 9bacbfef4c
commit 87834f5a0b
1 changed files with 8 additions and 11 deletions

View File

@ -11,6 +11,11 @@ class NewVisitorTest(unittest.TestCase):
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])
def test_can_start_a_list_and_retrieve_it_later(self): def test_can_start_a_list_and_retrieve_it_later(self):
# Edith has heard about a cool new online to-do app. She goes # Edith has heard about a cool new online to-do app. She goes
# to check out its homepage # to check out its homepage
@ -36,9 +41,7 @@ class NewVisitorTest(unittest.TestCase):
# "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) inputbox.send_keys(Keys.ENTER)
time.sleep(1) time.sleep(1)
table = self.browser.find_element_by_id('id_list_table') self.check_for_row_in_list_table('1: Buy peacock feathers')
rows = table.find_elements_by_tag_name('tr')
# self.assertTrue('1: Buy peacock feathers', [row.text for row in rows])
# There is still a text box inviting her to add another item. She # 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) # enters "Use peacock feathers to make a fly" (Edith is very methodical)
@ -48,14 +51,8 @@ class NewVisitorTest(unittest.TestCase):
time.sleep(1) time.sleep(1)
# The page updates again, and now shows both items on her list # The page updates again, and now shows both items on her list
table = self.browser.find_element_by_id('id_list_table') self.check_for_row_in_list_table('1: Buy peacock feathers')
rows = table.find_elements_by_tag_name('tr') self.check_for_row_in_list_table('2: Use peacock feathers to make a fly')
print(rows)
self.assertIn('1: Buy peacock feathers', [row.text for row in rows])
self.assertIn(
'2: Use peacock feathers to make a fly',
[row.text for row in rows]
)
# Edith wonders whether the site will remember her list. Then she sees # Edith wonders whether the site will remember her list. Then she sees
# that the site has generated a unique URL for her -- there is some # that the site has generated a unique URL for her -- there is some