test_main.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. def connexion_saucedemo(username, passwd, arg="--headless"):
  15. log.info("Test du Login avec succès")
  16. options = webdriver.FirefoxOptions()
  17. options.add_argument(arg)
  18. driver = webdriver.Firefox(options=options)
  19. driver.get("https://www.saucedemo.com/")
  20. username = driver.find_element(By.ID, "user-name")
  21. password = driver.find_element(By.ID, "password")
  22. login = driver.find_element(By.ID, "login-button")
  23. writeInInput(inputElement=username, text=username)
  24. writeInInput(password, text=passwd)
  25. login.click()
  26. log.info("")
  27. ##### MANEL
  28. ##### MATTHIEU
  29. def go_to_checkout():
  30. checkout = driver.find_element(By.CSS_SELECTOR, "#checkout")
  31. checkout.click()
  32. #@pytest.mark.skip("Je veux pas le faire")
  33. def test_affichage_Checkout():
  34. log.info("Test de la redirection sur la page de Checkout")
  35. #connexion Swag Labs
  36. #connexion_saucedemo("standard_user", "secret_sauce", "") --A DEBUGG
  37. options = webdriver.FirefoxOptions()
  38. options.add_argument("--headless")
  39. driver = webdriver.Firefox(options=options)
  40. driver.get("https://www.saucedemo.com/")
  41. assert (
  42. driver.current_url == "https://www.saucedemo.com/"
  43. ), "Nous ne somme pas sur la bonne page"
  44. username = driver.find_element(By.ID, "user-name")
  45. password = driver.find_element(By.ID, "password")
  46. login = driver.find_element(By.ID, "login-button")
  47. writeInInput(inputElement=username, text="standard_user")
  48. writeInInput(password, text="secret_sauce")
  49. login.click()
  50. assert (
  51. driver.current_url == "https://www.saucedemo.com/inventory.html"
  52. ), "Nous ne somme pas sur la bonne page"
  53. #ajout "Sauce Labs Bike Light" au panier -- A changer si Tiff implémente une fonction pour le faire
  54. item_lamp = driver.find_element(By.ID, "add-to-cart-sauce-labs-bike-light")
  55. item_lamp.click()
  56. #affichage panier -- A changer si Tiff implémente une fonction pour le faire
  57. panier_btn= driver.find_element(By.ID, "shopping_cart_container")
  58. panier_btn.click()
  59. #redirection vers la pade de checkout
  60. #go_to_checkout() -- A DEBUGG
  61. checkout_btn = driver.find_element(By.CSS_SELECTOR, "#checkout")
  62. checkout_btn.click()
  63. assert (
  64. driver.current_url == "https://www.saucedemo.com/checkout-step-one.html"
  65. ), "Nous ne somme pas sur la bonne page"
  66. driver.quit()
  67. ##### TIFF