test_sauce_demo_class.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. import os
  15. class TestSauceDemo():
  16. def is_windows():
  17. res = False
  18. if os.name == 'nt':
  19. res == True
  20. return res
  21. def writeInInput(self, inputElement, text):
  22. assert inputElement.is_displayed(), "Le champ texte n'est pas affiché"
  23. assert inputElement.is_enabled(), "Le champ texte n'est pas activé"
  24. inputElement.clear()
  25. inputElement.send_keys(text)
  26. def setup_method(self, method):
  27. log.info("Methode de SETUP AVANT CHAQUE TEST")
  28. if self.is_windows():
  29. self.driver = webdriver.Firefox()
  30. else:
  31. options = webdriver.FirefoxOptions()
  32. options.add_argument("--headless")
  33. self.driver = webdriver.Firefox(options=options)
  34. self.driver.get("http://www.saucedemo.com")
  35. assert (self.driver.current_url == "https://www.saucedemo.com/"), "Nous ne somme pas sur la bonne page"
  36. def teardown_method(self, method):
  37. log.info("Methode de TEARDOWN APRES CHAQUE TEST")
  38. self.driver.quit()
  39. def login(self):
  40. username = self.driver.find_element(By.ID, "user-name")
  41. password = self.driver.find_element(By.ID, "password")
  42. login = self.driver.find_element(By.ID, "login-button")
  43. writeInInput(inputElement=username, text="standard_user")
  44. writeInInput(password, text="secret_sauce")
  45. login.click()
  46. def logout(self):
  47. burger = self.driver.find_element(By.ID, "react-burger-menu-btn")
  48. burger.click()
  49. logout = self.driver.find_element(By.ID, "logout_sidebar_link")
  50. logout.click()
  51. def test_saucedemo_boutenbout(self):
  52. self.login()
  53. self.logout()
  54. def test_saucedemo_boutenbout_2(self):
  55. self.login()
  56. self.logout()
  57. def test_saucedemo_boutenbout_3(self):
  58. self.login()
  59. self.logout()
  60. ##### MANEL
  61. ##### MATTHIEU
  62. def go_to_checkout(self):
  63. checkout = self.driver.find_element(By.CSS_SELECTOR, "#checkout")
  64. checkout.click()
  65. ##### TIFF