Browse Source

last commit

Diane 1 year ago
parent
commit
10b2e5d3bc
1 changed files with 111 additions and 8 deletions
  1. 111 8
      test_saucedemo.py

+ 111 - 8
test_saucedemo.py

@@ -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,12 +142,11 @@ 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()
     options.add_argument('--headless')
-
     driver = webdriver.Firefox(options=options)
     
     #driver=webdriver.Chrome()
@@ -159,27 +158,131 @@ def test_ajout_panier():
 
     champ_username = driver.find_element(By.XPATH,'//*[@id="user-name"]')
 
-    log.info(champ_username)
+  
     champ_username.send_keys("standard_user")
-    log.info("texte du champ username"+champ_username.text) 
-    log.info("L'attribut du champ username est "+ champ_username.get_attribute("placeholder") )
+    
     assert champ_username.get_attribute("value")=="standard_user"
 
     champ_mdp = driver.find_element(By.CSS_SELECTOR,'#password')
     champ_mdp.send_keys("secret_sauce")
    # champ_mdp.send_keys(Keys.RETURN)
+    
     button_login = driver.find_element(By.ID,"login-button")
     element_visible_actif(button_login)
     button_login.click()
+
+    slip(2)
+
+
+
+
     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" 
+    
     button_add=driver.find_element(By.ID,"add-to-cart-sauce-labs-backpack")
+    element_visible_actif(button_add)
     button_add.click()
+    slip(2)
+
+    icone_panier=driver.find_element(By.CLASS_NAME,"shopping_cart_badge")
+    assert icone_panier.text=="1", "l'icone du panier nn'affiche pas 1"
+
+    button_add=driver.find_element(By.ID,"add-to-cart-sauce-labs-bolt-t-shirt")
+    element_visible_actif(button_add)
+    button_add.click()
+    slip(2)
+
+    icone_panier=driver.find_element(By.CLASS_NAME,"shopping_cart_badge")
+    assert icone_panier.text=="2", "l'icone du panier n'affiche pas 2"
+
+
+    
     button_panier=driver.find_element(By.CLASS_NAME,"shopping_cart_link")
+    element_visible_actif(button_panier)
     button_panier.click()
+    assert driver.current_url=="https://www.saucedemo.com/cart.html", "l'url de la page ouverte ("+ driver.current_url + ") n'est pas égal à https://www.saucedemo.com/cart.html"
+    
+    nom_article_panier=driver.find_element(By.ID,"item_4_title_link")
+    element_visible_actif(nom_article_panier)
+    assert nom_article_panier.text=="Sauce Labs Backpack"
+
+    nom_article_panier=driver.find_element(By.ID,"item_1_title_link")
+    element_visible_actif(nom_article_panier)
+    assert nom_article_panier.text=="Sauce Labs Bolt T-Shirt"
+    
+
+    
 
-    slip(2)
     driver.quit()
 
+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')
+    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_classname(driver,"shopping_cart_badge"):
+        badge_panier = driver.find_element(By.CLASS_NAME,"shopping_cart_badge")
+        nb_product_initial = int(badge_panier.text)
+    log.info(f"à la connexion, il y a {nb_product_initial} dans le panier")
+
+    # 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")
+    nb_product = int(badge_panier.text)
+    log.info(f"à l'ajout d'un article', il y a {nb_product} dans le panier")
+    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 nb_product_initial+1 == nb_product
+
+    # Vérification clic button "remove" change de texte vers "add to cart"
+    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")
+
+    driver.quit()
+
+
+
+
 def test_detail_article():
     
     #options = webdriver.FirefoxOptions()
@@ -232,4 +335,4 @@ def test_detail_article():
 
     
     slip(2)
-    driver.quit()
+    driver.quit()