2 Achegas e6074fdcad ... 663a93da9f

Autor SHA1 Mensaxe Data
  vdiez-devweb 663a93da9f resolve conflict git pull hai 1 ano
  vdiez-devweb ec8f57b631 Test button add to cart part 2 hai 1 ano
Modificáronse 1 ficheiros con 23 adicións e 10 borrados
  1. 23 10
      test_saucedemo.py

+ 23 - 10
test_saucedemo.py

@@ -212,13 +212,20 @@ def test_ajout_panier():
 
     driver.quit()
 
-def exists_element_by_class(driver, class_elt):
+def exists_element_by_classname(driver, class_elt):
     try:
         driver.find_element(By.CLASS_NAME,class_elt)
     except:
         return False
     return True
 
+def exists_element_by_id(driver, class_elt):
+    try:
+        driver.find_element(By.ID,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')
@@ -244,27 +251,33 @@ def test_click_button_add_to_cart():
 
     # 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"):
+    if exists_element_by_classname(driver,"shopping_cart_badge"):
         badge_panier = driver.find_element(By.CLASS_NAME,"shopping_cart_badge")
-        nb_product_initial = badge_panier.text
+        nb_product_initial = int(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()
+    log.info("click sur 'add to cart' change button and add a badge on icon cart")
     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")
+    nb_product = int(badge_panier.text)
+    log.info(f"à l'ajout d'un article', il y a {nb_product} 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")
+    assert False == exists_element_by_id(driver,"add-to-cart-sauce-labs-backpack")
+    assert True == exists_element_by_id(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
+    assert nb_product_initial+1 == nb_product
 
     # 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
+    button_remove = driver.find_element(By.ID,"remove-sauce-labs-backpack")
+    button_remove.click()
+    log.info("click sur 'Remove' change button and remove the badge on icon cart")
+    assert True == exists_element_by_id(driver,"add-to-cart-sauce-labs-backpack")
+    assert False == exists_element_by_id(driver,"remove-sauce-labs-backpack")
+    # Vérification button "cart" a un badge supprimé car 0 articles dans le panier
+    assert False == exists_element_by_classname(driver,"shopping_cart_badge")
 
 
     slip(2)