functional_tests.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. self.browser = webdriver.Chrome()
  9. def tearDown(self):
  10. self.browser.quit()
  11. def test_can_start_a_list_and_retrieve_it_later(self):
  12. self.browser.get('http://localhost:8000')
  13. self.assertIn('To-Do', self.browser.title)
  14. header_text = self.browser.find_element_by_tag_name('h1').text
  15. self.assertIn('To-Do', header_text)
  16. inputbox = self.browser.find_element_by_id('id_new_item')
  17. self.assertEqual(
  18. inputbox.get_attribute('placeholder'),
  19. 'Enter a to-do item'
  20. )
  21. # ITEM 1
  22. inputbox.send_keys('Buy rubber ducks')
  23. inputbox.send_keys(Keys.ENTER)
  24. time.sleep(3) # When in doubt, increase it / add a wait!
  25. table = self.browser.find_element_by_id('id_list_table')
  26. rows = table.find_elements_by_tag_name('tr')
  27. self.assertIn('1: Buy rubber ducks', [row.text for row in rows])
  28. # ITEM 2
  29. inputbox = self.browser.find_element_by_id('id_new_item')
  30. inputbox.send_keys('Buy squirrel suits')
  31. inputbox.send_keys(Keys.ENTER)
  32. time.sleep(3) # When in doubt, increase it / add a wait!
  33. table = self.browser.find_element_by_id('id_list_table')
  34. rows = table.find_elements_by_tag_name('tr')
  35. self.assertIn('2: Buy squirrel suits', [row.text for row in rows])
  36. # Done?
  37. self.fail('Finish the test!')
  38. if __name__ == '__main__':
  39. unittest.main(warnings='ignore')