├── .vscode └── settings.json ├── __pycache__ ├── constants.cpython-310.pyc ├── test_add_to_cart.cpython-310-pytest-7.1.2.pyc ├── test_lockedoutuser.cpython-310-pytest-7.1.2.pyc ├── test_loginproductscount.cpython-310-pytest-7.1.2.pyc ├── test_products_order_by_price.cpython-310-pytest-7.1.2.pyc ├── test_productsorder.cpython-310-pytest-7.1.2.pyc └── test_productsorderztoa.cpython-310-pytest-7.1.2.pyc ├── constants.py ├── data ├── products_order.xlsx └── products_order_za.xlsx ├── test_add_to_cart.py ├── test_lockedoutuser.py ├── test_loginproductscount.py ├── test_products_order_by_price.py ├── test_productsorder.py └── test_productsorderztoa.py /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "python.testing.pytestArgs": [ 3 | "." 4 | ], 5 | "python.testing.unittestEnabled": false, 6 | "python.testing.pytestEnabled": true 7 | } -------------------------------------------------------------------------------- /__pycache__/constants.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halitkalayci/selenium-advanced/e7b23ce033b19730371ed6d070f8c943b12819bc/__pycache__/constants.cpython-310.pyc -------------------------------------------------------------------------------- /__pycache__/test_add_to_cart.cpython-310-pytest-7.1.2.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halitkalayci/selenium-advanced/e7b23ce033b19730371ed6d070f8c943b12819bc/__pycache__/test_add_to_cart.cpython-310-pytest-7.1.2.pyc -------------------------------------------------------------------------------- /__pycache__/test_lockedoutuser.cpython-310-pytest-7.1.2.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halitkalayci/selenium-advanced/e7b23ce033b19730371ed6d070f8c943b12819bc/__pycache__/test_lockedoutuser.cpython-310-pytest-7.1.2.pyc -------------------------------------------------------------------------------- /__pycache__/test_loginproductscount.cpython-310-pytest-7.1.2.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halitkalayci/selenium-advanced/e7b23ce033b19730371ed6d070f8c943b12819bc/__pycache__/test_loginproductscount.cpython-310-pytest-7.1.2.pyc -------------------------------------------------------------------------------- /__pycache__/test_products_order_by_price.cpython-310-pytest-7.1.2.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halitkalayci/selenium-advanced/e7b23ce033b19730371ed6d070f8c943b12819bc/__pycache__/test_products_order_by_price.cpython-310-pytest-7.1.2.pyc -------------------------------------------------------------------------------- /__pycache__/test_productsorder.cpython-310-pytest-7.1.2.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halitkalayci/selenium-advanced/e7b23ce033b19730371ed6d070f8c943b12819bc/__pycache__/test_productsorder.cpython-310-pytest-7.1.2.pyc -------------------------------------------------------------------------------- /__pycache__/test_productsorderztoa.cpython-310-pytest-7.1.2.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halitkalayci/selenium-advanced/e7b23ce033b19730371ed6d070f8c943b12819bc/__pycache__/test_productsorderztoa.cpython-310-pytest-7.1.2.pyc -------------------------------------------------------------------------------- /constants.py: -------------------------------------------------------------------------------- 1 | DRIVER_PATH = "C:\chromedriver.exe" 2 | BASE_URL = "https://www.saucedemo.com/" 3 | USERNAME_INPUT_SELECTOR = "*[data-test=\"username\"]" 4 | LOCKED_OUT_USER = "locked_out_user" 5 | STANDARD_USER = "standard_user" 6 | PASSWORD_INPUT_SELECTOR = "*[data-test=\"password\"]" 7 | USER_PASSWORD="secret_sauce" 8 | LOGIN_BUTTON_SELECTOR = "*[data-test=\"login-button\"]" 9 | ERROR_ALERT_SELECTOR = "*[data-test=\"error\"]" 10 | LOCKED_OUT_USER_ERROR="Epic sadface: Sorry, this user has been locked out." 11 | INVENTORY_LIST = ".inventory_list" 12 | INVENTORY_ITEMS = ".inventory_list > .inventory_item" 13 | INVENTORY_ITEM_NAME = "inventory_item_name" 14 | Z_TO_A_OPTION="//*[@id='header_container']/div[2]/div[2]/span/select/option[2]" 15 | LOW_TO_HIGH_OPTION="//*[@value='lohi']" 16 | PRICE_CLASS="inventory_item_price" 17 | INVENTORY_BUTTON = "btn_inventory" 18 | CART_LINK = "shopping_cart_link" -------------------------------------------------------------------------------- /data/products_order.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halitkalayci/selenium-advanced/e7b23ce033b19730371ed6d070f8c943b12819bc/data/products_order.xlsx -------------------------------------------------------------------------------- /data/products_order_za.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halitkalayci/selenium-advanced/e7b23ce033b19730371ed6d070f8c943b12819bc/data/products_order_za.xlsx -------------------------------------------------------------------------------- /test_add_to_cart.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import time 3 | import json 4 | from selenium import webdriver 5 | from selenium.webdriver.common.by import By 6 | from selenium.webdriver.common.action_chains import ActionChains 7 | from selenium.webdriver.support import expected_conditions 8 | from selenium.webdriver.support.wait import WebDriverWait 9 | from selenium.webdriver.common.keys import Keys 10 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 11 | from constants import * 12 | 13 | class TestAddToCart: 14 | def setup_method(self, method): 15 | self.driver = webdriver.Chrome(DRIVER_PATH) 16 | self.vars = {} 17 | 18 | def teardown_method(self, method): 19 | self.driver.quit() 20 | 21 | def test_add_to_cart(self): 22 | self.driver.get(BASE_URL) 23 | self.driver.maximize_window() 24 | WebDriverWait(self.driver, 5).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, USERNAME_INPUT_SELECTOR))) 25 | self.driver.find_element(By.CSS_SELECTOR, USERNAME_INPUT_SELECTOR).click() 26 | self.driver.find_element(By.CSS_SELECTOR, USERNAME_INPUT_SELECTOR).send_keys(STANDARD_USER) 27 | WebDriverWait(self.driver, 5).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, PASSWORD_INPUT_SELECTOR))) 28 | self.driver.find_element(By.CSS_SELECTOR, PASSWORD_INPUT_SELECTOR).click() 29 | self.driver.find_element(By.CSS_SELECTOR, PASSWORD_INPUT_SELECTOR).send_keys(USER_PASSWORD) 30 | WebDriverWait(self.driver, 5).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, LOGIN_BUTTON_SELECTOR))) 31 | self.driver.find_element(By.CSS_SELECTOR, LOGIN_BUTTON_SELECTOR).click() 32 | WebDriverWait(self.driver, 5).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, INVENTORY_LIST))) 33 | #verilen ürün listesindeki tüm ürünleri sepete ekle.. 34 | excelData = ["Sauce Labs Onesie","Sauce Labs Bike Light","123"] 35 | products = self.driver.find_elements(By.CSS_SELECTOR,INVENTORY_ITEMS) 36 | 37 | for i in range(len(products)): 38 | productName = products[i].find_element(By.CLASS_NAME,INVENTORY_ITEM_NAME).text 39 | # excelden gelen veri bu ürün ismini içeriyor mu? 40 | if excelData.__contains__(productName): 41 | addToCartBtn = products[i].find_element(By.CLASS_NAME,INVENTORY_BUTTON) 42 | addToCartBtn.click() 43 | 44 | 45 | self.driver.find_element(By.CLASS_NAME,CART_LINK).click() 46 | cartItems = self.driver.find_elements(By.CLASS_NAME,'cart_item') 47 | 48 | 49 | for i in range(len(cartItems)): 50 | productName = cartItems[i].find_element(By.CLASS_NAME,INVENTORY_ITEM_NAME).text 51 | if excelData.__contains__(productName) == False: 52 | assert False 53 | assert True -------------------------------------------------------------------------------- /test_lockedoutuser.py: -------------------------------------------------------------------------------- 1 | # Generated by Selenium IDE 2 | import pytest 3 | import time 4 | import json 5 | from selenium import webdriver 6 | from selenium.webdriver.common.by import By 7 | from selenium.webdriver.common.action_chains import ActionChains 8 | from selenium.webdriver.support import expected_conditions 9 | from selenium.webdriver.support.wait import WebDriverWait 10 | from selenium.webdriver.common.keys import Keys 11 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 12 | from constants import * 13 | 14 | 15 | class Testlockedoutuser(): 16 | def setup_method(self, method): 17 | self.driver = webdriver.Chrome(DRIVER_PATH) 18 | self.vars = {} 19 | 20 | def teardown_method(self, method): 21 | self.driver.quit() 22 | 23 | def test_lockedoutuser(self): 24 | self.driver.get(BASE_URL) # refactor => magic string kaldırıldı.. 25 | self.driver.maximize_window() 26 | WebDriverWait(self.driver, 5).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, USERNAME_INPUT_SELECTOR))) # magic string kaldırıldı 27 | self.driver.find_element(By.CSS_SELECTOR, USERNAME_INPUT_SELECTOR).click() 28 | self.driver.find_element(By.CSS_SELECTOR, USERNAME_INPUT_SELECTOR).send_keys(LOCKED_OUT_USER) 29 | WebDriverWait(self.driver, 5).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, PASSWORD_INPUT_SELECTOR))) 30 | self.driver.find_element(By.CSS_SELECTOR, PASSWORD_INPUT_SELECTOR).send_keys(USER_PASSWORD) 31 | WebDriverWait(self.driver, 5).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, LOGIN_BUTTON_SELECTOR))) 32 | self.driver.find_element(By.CSS_SELECTOR, LOGIN_BUTTON_SELECTOR).click() 33 | assert self.driver.find_element(By.CSS_SELECTOR, ERROR_ALERT_SELECTOR).text == LOCKED_OUT_USER_ERROR 34 | 35 | -------------------------------------------------------------------------------- /test_loginproductscount.py: -------------------------------------------------------------------------------- 1 | # Generated by Selenium IDE 2 | import pytest 3 | import time 4 | import json 5 | from selenium import webdriver 6 | from selenium.webdriver.common.by import By 7 | from selenium.webdriver.common.action_chains import ActionChains 8 | from selenium.webdriver.support import expected_conditions 9 | from selenium.webdriver.support.wait import WebDriverWait 10 | from selenium.webdriver.common.keys import Keys 11 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 12 | from constants import * 13 | class Testloginproductscount(): 14 | def setup_method(self, method): 15 | self.driver = webdriver.Chrome(DRIVER_PATH) 16 | self.vars = {} 17 | 18 | def teardown_method(self, method): 19 | self.driver.quit() 20 | 21 | def test_loginproductscount(self): 22 | self.driver.get(BASE_URL) 23 | self.driver.maximize_window() 24 | WebDriverWait(self.driver, 5).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, USERNAME_INPUT_SELECTOR))) 25 | self.driver.find_element(By.CSS_SELECTOR, USERNAME_INPUT_SELECTOR).click() 26 | self.driver.find_element(By.CSS_SELECTOR, USERNAME_INPUT_SELECTOR).send_keys(STANDARD_USER) 27 | WebDriverWait(self.driver, 5).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, PASSWORD_INPUT_SELECTOR))) 28 | self.driver.find_element(By.CSS_SELECTOR, PASSWORD_INPUT_SELECTOR).click() 29 | self.driver.find_element(By.CSS_SELECTOR, PASSWORD_INPUT_SELECTOR).send_keys(USER_PASSWORD) 30 | WebDriverWait(self.driver, 5).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, LOGIN_BUTTON_SELECTOR))) 31 | self.driver.find_element(By.CSS_SELECTOR, LOGIN_BUTTON_SELECTOR).click() 32 | WebDriverWait(self.driver, 5).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, INVENTORY_LIST))) 33 | # inventory list içerisinde 6 adet eleman olduğunu doğrular 34 | elements = self.driver.find_elements(By.CSS_SELECTOR, INVENTORY_ITEMS) 35 | assert len(elements) == 6 36 | 37 | -------------------------------------------------------------------------------- /test_products_order_by_price.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import time 3 | import json 4 | from selenium import webdriver 5 | from selenium.webdriver.common.by import By 6 | from selenium.webdriver.common.action_chains import ActionChains 7 | from selenium.webdriver.support import expected_conditions 8 | from selenium.webdriver.support.wait import WebDriverWait 9 | from selenium.webdriver.common.keys import Keys 10 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 11 | from constants import * 12 | import openpyxl 13 | 14 | class TestProductsOrderByPrice: 15 | def setup_method(self, method): 16 | self.driver = webdriver.Chrome(DRIVER_PATH) 17 | self.vars = {} 18 | 19 | def teardown_method(self, method): 20 | self.driver.quit() 21 | 22 | def test_products_order(self): 23 | self.driver.get(BASE_URL) 24 | self.driver.maximize_window() 25 | WebDriverWait(self.driver, 5).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, USERNAME_INPUT_SELECTOR))) 26 | self.driver.find_element(By.CSS_SELECTOR, USERNAME_INPUT_SELECTOR).send_keys(STANDARD_USER) 27 | WebDriverWait(self.driver, 5).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, PASSWORD_INPUT_SELECTOR))) 28 | self.driver.find_element(By.CSS_SELECTOR, PASSWORD_INPUT_SELECTOR).send_keys(USER_PASSWORD) 29 | WebDriverWait(self.driver, 5).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, LOGIN_BUTTON_SELECTOR))) 30 | self.driver.find_element(By.CSS_SELECTOR, LOGIN_BUTTON_SELECTOR).click() 31 | # burdan sonrası değişmeli.. 32 | self.driver.find_element(By.XPATH,LOW_TO_HIGH_OPTION).click() 33 | # ürünler sıralandı.. 34 | # doğrulama!! 35 | products = self.driver.find_elements(By.CSS_SELECTOR,INVENTORY_ITEMS) 36 | # bu listeyi baştan sona gez, eğer o anki ürün fiyatı bi önceki ürün fiyatından düşükse 37 | # test hatalıdır.. 38 | # 10₺ 20₺ 30₺ 40₺ 39 | # 10₺ 20₺ 9₺ 20₺ 40 | lastPrice = -1 41 | testCase=True 42 | for i in range(len(products)): 43 | # ürünün fiyatı 44 | price = products[i].find_element(By.CLASS_NAME,PRICE_CLASS).text 45 | # $ işaretini kaldır ve floata çevir 46 | actualPrice = float(price.split('$')[1]) # 7.99 47 | # "123,456,789" => split(',') => ["123","456","789"] 48 | # $7.99 => split('$') => ['','7.99'] -> seperator 49 | if actualPrice < lastPrice: 50 | testCase=False 51 | #elif actualPrice == lastPrice: 52 | # biönceki ürün ile bu ürün arasında a-z sıralama yapılmış mı? 53 | else: 54 | lastPrice = actualPrice 55 | assert testCase == True 56 | 57 | -------------------------------------------------------------------------------- /test_productsorder.py: -------------------------------------------------------------------------------- 1 | # Generated by Selenium IDE 2 | import pytest 3 | import time 4 | import json 5 | from selenium import webdriver 6 | from selenium.webdriver.common.by import By 7 | from selenium.webdriver.common.action_chains import ActionChains 8 | from selenium.webdriver.support import expected_conditions 9 | from selenium.webdriver.support.wait import WebDriverWait 10 | from selenium.webdriver.common.keys import Keys 11 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 12 | import openpyxl 13 | from constants import * 14 | 15 | class TestTestproductsorder(): 16 | def setup_method(self, method): 17 | self.driver = webdriver.Chrome(DRIVER_PATH) 18 | self.vars = {} 19 | 20 | def teardown_method(self, method): 21 | self.driver.quit() 22 | 23 | def readItemsFromExcel(self): 24 | excelFile = openpyxl.load_workbook("data/products_order.xlsx") 25 | sheet = excelFile["Sheet1"] 26 | 27 | totalRows = sheet.max_row 28 | products=[] 29 | 30 | for i in range(2,totalRows+1): 31 | product_name = sheet.cell(i,1) 32 | products.append(product_name) 33 | 34 | return products 35 | 36 | def test_testproductsorder(self): 37 | self.driver.get(BASE_URL) 38 | self.driver.maximize_window() 39 | WebDriverWait(self.driver, 5).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, USERNAME_INPUT_SELECTOR))) 40 | self.driver.find_element(By.CSS_SELECTOR, USERNAME_INPUT_SELECTOR).send_keys(STANDARD_USER) 41 | WebDriverWait(self.driver, 5).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, PASSWORD_INPUT_SELECTOR))) 42 | self.driver.find_element(By.CSS_SELECTOR, PASSWORD_INPUT_SELECTOR).send_keys(USER_PASSWORD) 43 | WebDriverWait(self.driver, 5).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, LOGIN_BUTTON_SELECTOR))) 44 | self.driver.find_element(By.CSS_SELECTOR, LOGIN_BUTTON_SELECTOR).click() 45 | products = self.driver.find_elements(By.CLASS_NAME,INVENTORY_ITEM_NAME) # websiteden okuduğum 46 | # ürün isimlerini liste haline getir. 47 | productsFromExcel = self.readItemsFromExcel() # excelden okuduğum 48 | isAllProductsSame = len(products) == len(productsFromExcel) 49 | if isAllProductsSame==False: 50 | assert False 51 | for i in range(len(products)): 52 | if products[i].text != productsFromExcel[i].value: 53 | isAllProductsSame = False 54 | assert isAllProductsSame == True 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /test_productsorderztoa.py: -------------------------------------------------------------------------------- 1 | # Generated by Selenium IDE 2 | import pytest 3 | import time 4 | import json 5 | from selenium import webdriver 6 | from selenium.webdriver.common.by import By 7 | from selenium.webdriver.common.action_chains import ActionChains 8 | from selenium.webdriver.support import expected_conditions 9 | from selenium.webdriver.support.wait import WebDriverWait 10 | from selenium.webdriver.common.keys import Keys 11 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 12 | from constants import * 13 | from time import sleep 14 | import openpyxl 15 | class TestTestproductsorderztoa(): 16 | def setup_method(self, method): 17 | self.driver = webdriver.Chrome(DRIVER_PATH) 18 | self.vars = {} 19 | 20 | def teardown_method(self, method): 21 | self.driver.quit() 22 | 23 | 24 | def readItemsFromExcel(self): 25 | excelFile = openpyxl.load_workbook("data/products_order.xlsx") 26 | sheet = excelFile["Sheet1"] 27 | 28 | totalRows = sheet.max_row 29 | products=[] 30 | 31 | for i in range(2,totalRows+1): 32 | product_name = sheet.cell(i,1) 33 | products.append(product_name) 34 | 35 | return products 36 | 37 | def test_testproductsorderztoa(self): 38 | self.driver.get(BASE_URL) 39 | self.driver.maximize_window() 40 | WebDriverWait(self.driver, 5).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, USERNAME_INPUT_SELECTOR))) 41 | self.driver.find_element(By.CSS_SELECTOR, USERNAME_INPUT_SELECTOR).send_keys(STANDARD_USER) 42 | WebDriverWait(self.driver, 5).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, PASSWORD_INPUT_SELECTOR))) 43 | self.driver.find_element(By.CSS_SELECTOR, PASSWORD_INPUT_SELECTOR).send_keys(USER_PASSWORD) 44 | WebDriverWait(self.driver, 5).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, LOGIN_BUTTON_SELECTOR))) 45 | self.driver.find_element(By.CSS_SELECTOR, LOGIN_BUTTON_SELECTOR).click() 46 | self.driver.find_element(By.XPATH,Z_TO_A_OPTION).click() 47 | products = self.driver.find_elements(By.CLASS_NAME,INVENTORY_ITEM_NAME) 48 | productsFromExcel = self.readItemsFromExcel() 49 | isAllProductsSame = len(products) == len(productsFromExcel) 50 | if isAllProductsSame==False: 51 | assert False 52 | for i in range(len(products)): 53 | if products[i].text.strip() != productsFromExcel[i].value.strip(): 54 | isAllProductsSame = False 55 | assert isAllProductsSame == True 56 | 57 | 58 | 59 | 60 | --------------------------------------------------------------------------------