test_sauce_demo_class.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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(self):
  17. # oups
  18. res = False
  19. if os.name == "nt":
  20. res == True
  21. return res
  22. def writeInInput(self, inputElement, text):
  23. assert inputElement.is_displayed(), "Le champ texte n'est pas affiché"
  24. assert inputElement.is_enabled(), "Le champ texte n'est pas activé"
  25. inputElement.clear()
  26. inputElement.send_keys(text)
  27. def setup_method(self, method):
  28. log.info("Methode de SETUP AVANT CHAQUE TEST")
  29. if self.is_windows():
  30. self.driver = webdriver.Firefox()
  31. else:
  32. options = webdriver.FirefoxOptions()
  33. options.add_argument("--headless")
  34. self.driver = webdriver.Firefox(options=options)
  35. self.driver.get("http://www.saucedemo.com")
  36. assert (
  37. self.driver.current_url == "https://www.saucedemo.com/"
  38. ), "Nous ne somme pas sur la bonne page"
  39. def teardown_method(self, method):
  40. log.info("Methode de TEARDOWN APRES CHAQUE TEST")
  41. self.driver.quit()
  42. def login(self):
  43. username = self.driver.find_element(By.ID, "user-name")
  44. password = self.driver.find_element(By.ID, "password")
  45. login = self.driver.find_element(By.ID, "login-button")
  46. writeInInput(inputElement=username, text="standard_user")
  47. writeInInput(password, text="secret_sauce")
  48. login.click()
  49. def logout(self):
  50. burger = self.driver.find_element(By.ID, "react-burger-menu-btn")
  51. burger.click()
  52. logout = self.driver.find_element(By.ID, "logout_sidebar_link")
  53. logout.click()
  54. @pytest.mark.skip("")
  55. def test_saucedemo_boutenbout(self):
  56. self.login()
  57. self.logout()
  58. def add_item(self, item):
  59. self.driver.find_element(By.ID, f"add-to-cart-sauce-labs-{item}").click()
  60. ##### MATTHIEU
  61. def go_to_checkout(self):
  62. checkout = self.driver.find_element(By.CSS_SELECTOR, "#checkout")
  63. checkout.click()
  64. # @pytest.mark.skip("")
  65. def test_affichage_Checkout(self):
  66. log.info("Test de la redirection sur la page de Checkout")
  67. # connexion Swag Labs
  68. self.login()
  69. # ajout "Sauce Labs Bike Light" au panier -- A changer si Tiff implémente une fonction pour le faire
  70. item_lamp = self.driver.find_element(By.ID, "add-to-cart-sauce-labs-bike-light")
  71. item_lamp.click()
  72. # affichage panier -- A changer si Tiff implémente une fonction pour le faire
  73. panier_btn = self.driver.find_element(By.ID, "shopping_cart_container")
  74. panier_btn.click()
  75. # redirection vers la page de checkout
  76. self.go_to_checkout()
  77. assert (
  78. self.driver.current_url
  79. == "https://www.saucedemo.com/checkout-step-one.html"
  80. ), "Nous ne somme pas sur la bonne page"
  81. ##### TIFF
  82. def test_add_item(self):
  83. self.login()
  84. sauce_labs_item = self.add_item("backpack")
  85. shopping_container = self.driver.find_element(By.ID, "shopping_cart_container")
  86. assert (
  87. sauce_labs_item != shopping_container.text
  88. ), f"L'item {sauce_labs_item} ne correspond pas à l'item {shopping_container.text} présent dans le panier."
  89. log.info(
  90. f"L'item : {shopping_container.text} a été ajouté et l'item : {sauce_labs_item} était attendu"
  91. )