functional_tests.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 test_can_start_a_list_and_retrieve_it_later(self):
  11. # Edith has heard about a cool new online to-do app. She goes
  12. # to check out its homepage
  13. self.browser.get('http://localhost:8000')
  14. # She notices the page title and header mention to-do lists
  15. self.assertIn('MovieLib', self.browser.title)
  16. header_text = self.browser.find_element_by_tag_name('h1').text
  17. self.assertIn('Your Movie list', header_text)
  18. # She is invited to enter a to-do item straight away
  19. inputbox = self.browser.find_element_by_id('input-new-movie')
  20. self.assertEqual(
  21. inputbox.get_attribute('placeholder'),
  22. 'Enter a movie title'
  23. )
  24. # She types "Inception" into a text box
  25. inputbox.send_keys('Inception')
  26. # When she hits enter, the page updates, and now the page lists
  27. # "1: Inception" as an item in a to-do list table
  28. inputbox.send_keys(Keys.ENTER)
  29. time.sleep(1)
  30. table = self.browser.find_element_by_id('movie-table')
  31. rows = table.find_elements_by_tag_name('tr')
  32. self.assertTrue(
  33. any(row.text == '1: Inception' for row in rows)
  34. )
  35. # There is still a text box inviting her to add another item. She
  36. # enters "Armageddon"
  37. self.fail('Finish the test!')
  38. # She is invited to enter a to-do item straight away
  39. if __name__ == '__main__':
  40. unittest.main(warnings='ignore')