tests-fonctionnels.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. from selenium import webdriver
  2. import unittest
  3. import requests
  4. class NewVisitorTest(unittest.TestCase):
  5. def setUp(self):
  6. self.browser = webdriver.Firefox()
  7. def tearDown(self):
  8. self.browser.quit()
  9. def test_mini_server_home(self):
  10. # Edith has heard about a cool new online to-do app. She goes
  11. # to check out its homepage
  12. self.browser.get('http://localhost:8081')
  13. # She notices the page title and header mention to-do lists
  14. self.assertIn('Mini-Serveur', self.browser.title)
  15. r = requests.get("http://localhost:8081")
  16. status_code = r.status_code
  17. self.assertEqual(status_code, 200)
  18. #print(self.browser.find_elements_by_tag_name('a'))
  19. # She is invited to enter a to-do item straight away
  20. # print(browser.find_elements_by_tag_name('a'))
  21. def test_mini_server_not_found(self):
  22. # Edith has heard about a cool new online to-do app. She goes
  23. # to check out its homepage
  24. self.browser.get('http://localhost:8081/not-found')
  25. # She notices the page title and header mention to-do lists
  26. r = requests.get("http://localhost:8081/not-found")
  27. status_code = r.status_code
  28. self.assertEqual(status_code, 404)
  29. # # Instance de Firefox contrôlée par webdriver
  30. # browser = webdriver.Firefox()
  31. # # On pointe ce browser vers l'URL de notre mini-serveur
  32. # browser.get('http://localhost:8081')
  33. # # En toute logique, on voudrait que le HTML généré par notre serveur ait un titre
  34. # assert 'Mini-Serveur' in browser.title
  35. # r = requests.get("http://localhost:8081")
  36. # # print(r.status_code)
  37. # print(browser.find_elements_by_tag_name('a'))
  38. # browser.quit()
  39. if __name__ == '__main__':
  40. unittest.main(warnings='ignore')