Sfoglia il codice sorgente

renommage test_main en main + ajout fichier classe

Gogs 1 anno fa
parent
commit
4c5c38ebac
2 ha cambiato i file con 69 aggiunte e 4 eliminazioni
  1. 5 4
      main.py
  2. 64 0
      test_sauce_demo_class.py

+ 5 - 4
test_main.py → main.py

@@ -13,12 +13,13 @@ from selenium.webdriver.firefox.options import Options
 from test_saucedemo import writeInInput
 
 
-def connexion_saucedemo(username, passwd, arg="--headless"):
+def connexion_saucedemo(username, passwd):
     log.info("Test du Login avec succès")
     options = webdriver.FirefoxOptions()
-    options.add_argument(arg)
+    options.add_argument("--headless")
 
     driver = webdriver.Firefox(options=options)
+
     driver.get("https://www.saucedemo.com/")
 
     username = driver.find_element(By.ID, "user-name")
@@ -28,7 +29,7 @@ def connexion_saucedemo(username, passwd, arg="--headless"):
     writeInInput(inputElement=username, text=username)
     writeInInput(password, text=passwd)
     login.click()
-    log.info("")
+    
 
 
 ##### MANEL
@@ -40,7 +41,7 @@ def go_to_checkout():
     checkout = driver.find_element(By.CSS_SELECTOR, "#checkout")
     checkout.click()
 
-#@pytest.mark.skip("Je veux pas le faire")
+@pytest.mark.skip("Je veux pas le faire")
 def test_affichage_Checkout():
     log.info("Test de la redirection sur la page de Checkout")
 

+ 64 - 0
test_sauce_demo_class.py

@@ -0,0 +1,64 @@
+##### IMPORT
+import pytest
+import logging as log
+import time
+from selenium import webdriver
+from selenium.webdriver.common.by import By
+from selenium.webdriver.common.keys import Keys
+from selenium.webdriver.support import expected_conditions as EC
+from selenium.common.exceptions import TimeoutException
+from selenium.webdriver.support.ui import WebDriverWait
+from selenium.webdriver.support.ui import Select
+from selenium.webdriver.firefox.options import Options
+from test_saucedemo import writeInInput
+
+
+
+class TestSauceDemo():
+
+    def writeInInput(self, inputElement, text):
+        assert inputElement.is_displayed(), "Le champ texte n'est pas affiché"
+        assert inputElement.is_enabled(), "Le champ texte n'est pas activé"
+        inputElement.clear()
+        inputElement.send_keys(text)
+
+    def setup_method(self, method):
+        log.info("Methode de SETUP AVANT CHAQUE TEST")
+        self.driver = webdriver.Firefox()
+        self.driver.get("http://www.saucedemo.com")
+        #TODO ASSERT
+
+    def teardown_method(self, method):
+        log.info("Methode de TEARDOWN APRES CHAQUE TEST")
+        self.driver.quit()
+    
+    def login(self):
+        username = self.driver.find_element(By.ID, "user-name")
+        password = self.driver.find_element(By.ID, "password")
+        login = self.driver.find_element(By.ID, "login-button")
+
+        writeInInput(inputElement=username, text="standard_user")
+        writeInInput(password, text="secret_sauce")
+        login.click()
+
+    def logout(self):
+        burger = self.driver.find_element(By.ID, "react-burger-menu-btn")
+        burger.click()
+        logout=  self.driver.find_element(By.ID, "logout_sidebar_link")
+        logout.click()
+
+    def go_to_checkout(self):
+        checkout = driver.find_element(By.CSS_SELECTOR, "#checkout")
+        checkout.click()
+
+    def test_saucedemo_boutenbout(self):
+        self.login()
+        self.logout()
+
+    def test_saucedemo_boutenbout_2(self):
+        self.login()
+        self.logout()
+
+    def test_saucedemo_boutenbout_3(self):
+        self.login()
+        self.logout()