functional_tests.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. inputbox.send_keys('Buy peacock feathers')
  22. inputbox.send_keys(Keys.ENTER)
  23. time.sleep(1)
  24. table = self.browser.find_element_by_id('id_list_table')
  25. rows = table.find_elements_by_tag_name('tr')
  26. self.assertTrue(
  27. any(row.text == '1: Buy peacock feathers' for row in rows),
  28. "New to-do item did not show up in table!"
  29. )
  30. self.fail('Finish the test!')
  31. if __name__ == '__main__':
  32. unittest.main(warnings='ignore')