functional_tests.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from selenium import webdriver
  2. from selenium.webdriver.common.keys import Keys
  3. import time
  4. import unittest
  5. class NewVisitorTest(unittest.TestCase):
  6. def setUp(self):
  7. self.browser = webdriver.Firefox()
  8. def tearDown(self):
  9. self.browser.quit()
  10. def check_for_row_in_list_table(self, row_text):
  11. table = self.browser.find_element_by_id('movie-table')
  12. rows = table.find_elements_by_tag_name('tr')
  13. self.assertIn(row_text, [row.text for row in rows])
  14. def test_can_start_a_list_and_retrieve_it_later(self):
  15. # Edith has heard about a cool new online to-do app. She goes
  16. # to check out its homepage
  17. self.browser.get('http://localhost:8000')
  18. # She notices the page title and header mention to-do lists
  19. self.assertIn('MovieLib', self.browser.title)
  20. header_text = self.browser.find_element_by_tag_name('h1').text
  21. self.assertIn('Your Movie list', header_text)
  22. # She is invited to enter a to-do item straight away
  23. inputbox = self.browser.find_element_by_id('input-new-movie')
  24. self.assertEqual(
  25. inputbox.get_attribute('placeholder'),
  26. 'Enter a movie title'
  27. )
  28. # She types "Inception" into a text box
  29. inputbox.send_keys('Inception')
  30. # When she hits enter, the page updates, and now the page lists
  31. # "1: Inception" as an item in a to-do list table
  32. inputbox.send_keys(Keys.ENTER)
  33. time.sleep(1)
  34. self.check_for_row_in_list_table('1: Inception')
  35. inputbox = self.browser.find_element_by_id('input-new-movie')
  36. inputbox.send_keys('The Sixth Sense')
  37. inputbox.send_keys(Keys.ENTER)
  38. time.sleep(1)
  39. self.check_for_row_in_list_table('1: Inception')
  40. self.check_for_row_in_list_table('2: The Sixth Sense')
  41. # There is still a text box inviting her to add another item. She
  42. # enters "Armageddon"
  43. # self.fail('Finish the test!')
  44. # She is invited to enter a to-do item straight away
  45. if __name__ == '__main__':
  46. unittest.main(warnings='ignore')