|
@@ -8,7 +8,7 @@ from selenium.webdriver.support.ui import WebDriverWait
|
|
|
from selenium.webdriver.support import expected_conditions as EC
|
|
|
from selenium.common.exceptions import TimeoutException
|
|
|
|
|
|
-debug = False
|
|
|
+debug = True
|
|
|
|
|
|
def slip(secondes):
|
|
|
if debug:
|
|
@@ -142,7 +142,7 @@ def test_login_OK_logout_saucedemo():
|
|
|
slip(2)
|
|
|
driver.quit()
|
|
|
|
|
|
-#@pytest.mark.skip("JE VEUX PAS LE FAIRE")
|
|
|
+@pytest.mark.skip("JE VEUX PAS LE FAIRE")
|
|
|
def test_ajout_panier():
|
|
|
|
|
|
options = webdriver.FirefoxOptions()
|
|
@@ -177,5 +177,62 @@ def test_ajout_panier():
|
|
|
button_panier=driver.find_element(By.CLASS_NAME,"shopping_cart_link")
|
|
|
button_panier.click()
|
|
|
|
|
|
+ slip(2)
|
|
|
+ driver.quit()
|
|
|
+
|
|
|
+def exists_element_by_class(driver, class_elt):
|
|
|
+ try:
|
|
|
+ driver.find_element(By.CLASS_NAME,class_elt)
|
|
|
+ except:
|
|
|
+ return False
|
|
|
+ return True
|
|
|
+
|
|
|
+#@pytest.mark.skip("JE VEUX PAS LE FAIRE")
|
|
|
+def test_click_button_add_to_cart():
|
|
|
+ log.info('Test sur le bouton "add to cart" change pour "remove" quand on clic dessus + bouton panier s\'incrémente')
|
|
|
+ options = webdriver.FirefoxOptions()
|
|
|
+ options.add_argument('--headless')
|
|
|
+ driver = webdriver.Firefox(options=options)
|
|
|
+
|
|
|
+ # driver=webdriver.Chrome()
|
|
|
+
|
|
|
+ url_sauce_demo = "https://www.saucedemo.com/"
|
|
|
+ driver.get(url_sauce_demo)
|
|
|
+
|
|
|
+ # Vérification login
|
|
|
+ champ_username = driver.find_element(By.XPATH,'//*[@id="user-name"]')
|
|
|
+ champ_username.send_keys("standard_user")
|
|
|
+ assert champ_username.get_attribute("value") == "standard_user"
|
|
|
+ champ_mdp = driver.find_element(By.CSS_SELECTOR,'#password')
|
|
|
+ champ_mdp.send_keys("secret_sauce")
|
|
|
+ button_login = driver.find_element(By.ID,"login-button")
|
|
|
+ element_visible_actif(button_login)
|
|
|
+ button_login.click()
|
|
|
+ assert driver.current_url == "https://www.saucedemo.com/inventory.html", "l'url de la page ouverte ("+ driver.current_url + ") n'est pas égal à https://www.saucedemo.com/inventory.html"
|
|
|
+
|
|
|
+ # Récupérer état button "cart" : s'il a un badge récupérer le n° d'articles ajoutés, sinon n° article =0
|
|
|
+ nb_product_initial = 0
|
|
|
+ if exists_element_by_class(driver,"add-to-cart-sauce-labs-backpack") and exists_element_by_class(driver,"shopping_cart_badge"):
|
|
|
+ badge_panier = driver.find_element(By.CLASS_NAME,"shopping_cart_badge")
|
|
|
+ nb_product_initial = badge_panier.text
|
|
|
+ log.info(f"à la connexion, il y a {nb_product_initial} dans le panier")
|
|
|
+ slip(2)
|
|
|
+
|
|
|
+ # Vérification clic button "add to cart" change de texte vers "remove"
|
|
|
+ button_add = driver.find_element(By.ID,"add-to-cart-sauce-labs-backpack")
|
|
|
+ button_add.click()
|
|
|
+ badge_panier = driver.find_element(By.CLASS_NAME,"shopping_cart_badge")
|
|
|
+ log.info(f"à l'ajout d'un article', il y a {badge_panier.text} dans le panier")
|
|
|
+ slip(2)
|
|
|
+ assert False == exists_element_by_class(driver,"add-to-cart-sauce-labs-backpack")
|
|
|
+ assert True == exists_element_by_class(driver,"remove-sauce-labs-backpack")
|
|
|
+ # et que le button "cart" a un badge avec n° incrémenté
|
|
|
+ assert str(nb_product_initial+1) == badge_panier.text
|
|
|
+
|
|
|
+ # Vérification clic button "remove" change de texte vers "add to cart"
|
|
|
+ log.info("click sur 'add to cart' change button and add a badge on icon cart")
|
|
|
+
|
|
|
+ # Vérification button "cart" a un badge avec n° incrémenté ou supprimé si de 1 à 0
|
|
|
+
|
|
|
slip(2)
|
|
|
driver.quit()
|