test_sauce_demo_class.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ##### IMPORT
  2. import pytest
  3. import logging as log
  4. import time
  5. from selenium import webdriver
  6. from selenium.webdriver.common.by import By
  7. from selenium.webdriver.common.keys import Keys
  8. from selenium.webdriver.support import expected_conditions as EC
  9. from selenium.common.exceptions import TimeoutException
  10. from selenium.webdriver.support.ui import WebDriverWait
  11. from selenium.webdriver.support.ui import Select
  12. from selenium.webdriver.firefox.options import Options
  13. from test_saucedemo import writeInInput
  14. class TestSauceDemo():
  15. def writeInInput(self, inputElement, text):
  16. assert inputElement.is_displayed(), "Le champ texte n'est pas affiché"
  17. assert inputElement.is_enabled(), "Le champ texte n'est pas activé"
  18. inputElement.clear()
  19. inputElement.send_keys(text)
  20. def setup_method(self, method):
  21. log.info("Methode de SETUP AVANT CHAQUE TEST")
  22. self.driver = webdriver.Firefox()
  23. self.driver.get("http://www.saucedemo.com")
  24. #TODO ASSERT
  25. def teardown_method(self, method):
  26. log.info("Methode de TEARDOWN APRES CHAQUE TEST")
  27. self.driver.quit()
  28. def login(self):
  29. username = self.driver.find_element(By.ID, "user-name")
  30. password = self.driver.find_element(By.ID, "password")
  31. login = self.driver.find_element(By.ID, "login-button")
  32. writeInInput(inputElement=username, text="standard_user")
  33. writeInInput(password, text="secret_sauce")
  34. login.click()
  35. def logout(self):
  36. burger = self.driver.find_element(By.ID, "react-burger-menu-btn")
  37. burger.click()
  38. logout= self.driver.find_element(By.ID, "logout_sidebar_link")
  39. logout.click()
  40. def go_to_checkout(self):
  41. checkout = driver.find_element(By.CSS_SELECTOR, "#checkout")
  42. checkout.click()
  43. def test_saucedemo_boutenbout(self):
  44. self.login()
  45. self.logout()
  46. def test_saucedemo_boutenbout_2(self):
  47. self.login()
  48. self.logout()
  49. def test_saucedemo_boutenbout_3(self):
  50. self.login()
  51. self.logout()