tests.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from django.test import LiveServerTestCase
  2. from selenium import webdriver
  3. from selenium.webdriver.common.keys import Keys
  4. import time
  5. class NewVisitorTest(LiveServerTestCase):
  6. def setUp(self):
  7. #self.browser = webdriver.Firefox()
  8. self.browser = webdriver.Chrome()
  9. def tearDown(self):
  10. self.browser.quit()
  11. def check_for_row_in_list_table(self, row_text):
  12. table = self.browser.find_element_by_id('id_list_table')
  13. rows = table.find_elements_by_tag_name('tr')
  14. self.assertIn(row_text, [row.text for row in rows])
  15. def test_can_start_a_list_and_retrieve_it_later(self):
  16. self.browser.get(self.live_server_url)
  17. self.assertIn('To-Do', self.browser.title)
  18. header_text = self.browser.find_element_by_tag_name('h1').text
  19. self.assertIn('To-Do', header_text)
  20. inputbox = self.browser.find_element_by_id('id_new_item')
  21. self.assertEqual(
  22. inputbox.get_attribute('placeholder'),
  23. 'Enter a to-do item'
  24. )
  25. # ITEM 1
  26. inputbox.send_keys('Buy rubber ducks')
  27. inputbox.send_keys(Keys.ENTER)
  28. time.sleep(1)
  29. self.check_for_row_in_list_table('1: Buy rubber ducks')
  30. # ITEM 2
  31. inputbox = self.browser.find_element_by_id('id_new_item')
  32. inputbox.send_keys('Buy squirrel suits')
  33. inputbox.send_keys(Keys.ENTER)
  34. time.sleep(1)
  35. self.check_for_row_in_list_table('1: Buy rubber ducks')
  36. self.check_for_row_in_list_table('2: Buy squirrel suits')
  37. # Done?
  38. self.fail('Finish the test!')