test_sauce_demo_class.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 (self.driver.current_url == "https://www.saucedemo.com/"), "Nous ne somme pas sur la bonne page"
  37. def teardown_method(self, method):
  38. log.info("Methode de TEARDOWN APRES CHAQUE TEST")
  39. self.driver.quit()
  40. def login(self):
  41. username = self.driver.find_element(By.ID, "user-name")
  42. password = self.driver.find_element(By.ID, "password")
  43. login = self.driver.find_element(By.ID, "login-button")
  44. writeInInput(inputElement=username, text="standard_user")
  45. writeInInput(password, text="secret_sauce")
  46. login.click()
  47. def logout(self):
  48. burger = self.driver.find_element(By.ID, "react-burger-menu-btn")
  49. burger.click()
  50. logout = self.driver.find_element(By.ID, "logout_sidebar_link")
  51. logout.click()
  52. @pytest.mark.skip("")
  53. def test_saucedemo_boutenbout(self):
  54. self.login()
  55. self.logout()
  56. ##### MANEL
  57. ##### MATTHIEU
  58. def go_to_checkout(self):
  59. checkout = self.driver.find_element(By.CSS_SELECTOR, "#checkout")
  60. checkout.click()
  61. #@pytest.mark.skip("")
  62. def test_affichage_Checkout(self):
  63. log.info("Test de la redirection sur la page de Checkout")
  64. #connexion Swag Labs
  65. self.login()
  66. #ajout "Sauce Labs Bike Light" au panier -- A changer si Tiff implémente une fonction pour le faire
  67. item_lamp = self.driver.find_element(By.ID, "add-to-cart-sauce-labs-bike-light")
  68. item_lamp.click()
  69. #affichage panier -- A changer si Tiff implémente une fonction pour le faire
  70. panier_btn= self.driver.find_element(By.ID, "shopping_cart_container")
  71. panier_btn.click()
  72. #redirection vers la page de checkout
  73. self.go_to_checkout()
  74. assert (
  75. self.driver.current_url == "https://www.saucedemo.com/checkout-step-one.html"
  76. ), "Nous ne somme pas sur la bonne page"
  77. ##### TIFF