class FiltersPage(BasePage): log = cl.customLogger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver self.nav = NavigationPage(driver) #Loctors _clothes_page = "//a[@href='http://localhost/prestashop/3-clothes']" #by xpath _men_page = '//ul[@class="category-sub-menu"]//a[contains(text(),"Men")]' #byXpath _man_collapse_menu = '//div[@id="left-column"]//ul[@class="category-sub-menu"]/li[1]/div[1]]' #byXpath _woman_page = '//ul[@class="category-sub-menu"]//a[@href="http://localhost/prestashop/5-women"]' #byXpath _woman_collapse_menu = '//div[@id="left-column"]//ul[@class="category-sub-menu"]/li[2]/div[1]' #byXpath _woman_collapse_menu_bluzki = '//ul[@class="category-sub-menu"]/li[2]//ul[@class="category-sub-menu"]//a[contains(text(),"Bluzki")]' # clothes #sizes: _size_S = '//div[@id="search_filters"]/section[2]/ul/li[1]//span[@class="custom-checkbox"]' _size_M = '//div[@id="search_filters"]/section[2]/ul/li[2]//span[@class="custom-checkbox"]' _size_L = '//div[@id="search_filters"]/section[2]/ul/li[3]//span[@class="custom-checkbox"]' _size_XL = '//div[@id="search_filters"]/section[2]/ul/li[4]//span[@class="custom-checkbox"]' #colors: _white_color = '//div[@id="search_filters"]/section[3]/ul/li[1]//span[@class="custom-checkbox"]/input' _black_color = '//div[@id="search_filters"]/section[3]/ul/li[2]//span[@class="custom-checkbox"]/input' #prices: _price_cat1 = '//div[@id="search_filters"]/section[4]/ul/li[1]//span[@class="custom-checkbox"]' _price_cat2 = '//div[@id="search_filters"]/section[4]/ul/li[2]//span[@class="custom-checkbox"]' _price_cat3 = '//div[@id="search_filters"]/section[4]/ul/li[3]//span[@class="custom-checkbox"]' _price_cat4 = '//div[@id="search_filters"]/section[4]/ul/li[4]//span[@class="custom-checkbox"]' def goToMenPageSuccessful(self): self.nav.goToClothesPage() self.elementClick(locator=self._men_page, locatorType='xpath') self.waitForElement( locator= '//div[@class="block-category card card-block hidden-sm-down"]/h1[contains(text(), "Men")]', locatorType='xpath') result = self.isElementPresent( locator= '//div[@class="block-category card card-block hidden-sm-down"]/h1[contains(text(), "Men")]', locatorType='xpath') return result def clothesWomenBluzkiPage(self): self.waitForElement( locator= "//div[@id='js-product-list']/div[@class='products row']/article[1]" ) products = self.driver.find_elements( By.XPATH, "//div[@id='js-product-list']/div[@class='products row']//h1[@class='h3 product-title']/a" ) for el in products: product = el.text if 'Bluzka' not in product: return False return True def clothesPagehoverOverMenu(self): self.nav.backToHomePage() element = self.driver.find_element(By.XPATH, self._clothes_page) actions = ActionChains(self.driver) actions.move_to_element(element).perform() self.waitForElement(locator="//ul[@id='top-menu']/li[1]/div", locatorType="xpath") self.elementClick( locator= "//ul[@id='top-menu']/li[1]/div/ul/li[2]//a[contains(text(),'Bluzki')]", locatorType="xpath") def collapseMenuWomenBlouse(self): self.nav.goToClothesPage() self.waitForElement(locator=self._woman_collapse_menu, locatorType="xpath") self.elementClick(locator=self._woman_collapse_menu, locatorType="xpath") self.waitForElement(locator=self._woman_collapse_menu_bluzki, locatorType='xpath') self.elementClick(locator=self._woman_collapse_menu_bluzki, locatorType='xpath') def multipleFiltersClick(self): # Clicks on the color and size clothes self.nav.goToClothesPage() self.driver.execute_script("window.scrollBy(0, -300);") self.waitForElement(locator='search_filters') self.elementClick(locator=self._size_M, locatorType='xpath') time.sleep(2) self.elementClick(locator=self._black_color, locatorType='xpath') time.sleep(2) def multipleFiltersSuccessful(self): # Checks if selected products are the same as products in database products = [] text_list = [] product_list = self.driver.find_elements( By.XPATH, "//div[@class='products row']/article//h1[@class='h3 product-title']/a" ) for product in product_list: hr = product.text text_list.append(hr.lower()) file = open("product_list_black_m.txt", "r", encoding="utf-8") product_list_database = file.readlines() for line in product_list_database: el = line.rstrip() products.append(el.lower()) for line in products: if line not in text_list: return False return True
class CartPage(BasePage): log = cl.customLogger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver self.nav = NavigationPage(self.driver) self.lp = LoginPage(self.driver) #Loctors _cart = "_desktop_cart" #byID _add_to_cart = "//form[@id='add-to-cart-or-refresh']//button[@type='submit']" _panda_tshirt = "//div[@id='js-product-list']/div[@class='products row']//a[contains(text(),'T-shirt Panda')]" # byXpath _bluzka_Fiona = "//div[@class='products row']//a[contains(text(),'Bluzka Fiona')]" _select_size = "group[1]" #byName _size_M = "//select[@name='group[1]']/option[@title='M']" _color = "group[2]" #byName _quantity = "quantity_wanted" #byID _go_to_fulfill_the_order_button = "//div[@class='modal-content']//a" #byxpath _continue_shopping_button = "//button[contains(text(),'Kontynuuj zakupy')]" #byxpath _num_of_products_in_cart = "//div[@id='cart-subtotal-products']/span[1]" _first_product_trashcan = "//ul[@class='cart-items']//a[@href='http://localhost/prestashop/koszyk?delete=1&id_product=30&id_product_attribute=150&token=41accb438c23197911beb3a379f403de']/i[.='delete']" _products_in_cart = "//div[@class='card cart-container']//ul[@class='cart-items']/li" _touchspin_down = "//div[@class='card cart-container']//li[1]/div[@class='product-line-grid']//span[@class='input-group-btn-vertical']/button[2]" def getProductToCartPanda(self, quantity): self.nav.goToClothesPage() self.waitForElement(locator="//div[@id='js-product-list']/div[@class='products row']/article[1]", locatorType='xpath') self.elementClick(locator=self._panda_tshirt, locatorType='xpath') self.waitForElement(locator=self._size_M, locatorType="xpath") self.elementClick(locator=self._select_size, locatorType="name") self.elementClick(locator=self._size_M, locatorType="xpath") self.elementClick(locator=self._color, locatorType="name") self.clearField(locator=self._quantity) self.sendKeys(quantity, locator=self._quantity) time.sleep(2) self.elementClick(locator=self._add_to_cart, locatorType="xpath") self.waitForElement(locator="cart-content", locatorType="class") def getProductToCartFiona(self,quantity): self.nav.goToClothesPage() self.waitForElement(locator=self._bluzka_Fiona, locatorType='xpath') self.elementClick(locator=self._bluzka_Fiona, locatorType='xpath') self.waitForElement(locator=self._add_to_cart, locatorType="xpath") self.elementClick(locator=self._select_size, locatorType="name") self.elementClick(locator=self._size_M, locatorType="xpath") self.elementClick(locator=self._color, locatorType="name") self.clearField(locator=self._quantity) self.sendKeys(quantity, locator=self._quantity) self.elementClick(locator=self._add_to_cart, locatorType="xpath") self.waitForElement(locator=self._go_to_fulfill_the_order_button, locatorType="xpath") def getFewProductsToCart(self, quantity): self.getProductToCartPanda(quantity) self.elementClick(locator=self._continue_shopping_button, locatorType="xpath") self.waitForElement(locator=self._select_size, locatorType="name") time.sleep(2) self.getProductToCartFiona(quantity) self.elementClick(locator=self._go_to_fulfill_the_order_button, locatorType="xpath") self.waitForElement(locator="cart-detailed-totals",locatorType="class") def getFewProductsToCartSuccessful(self, quantity): self.getFewProductsToCart(quantity) num = self.driver.find_element(By.XPATH, self._num_of_products_in_cart).text if str((quantity*2)) in str(num): result = True else: result = False return result def priceOfProductsInBasket(self,quantity): self.getFewProductsToCart(quantity) elements = self.driver.find_elements(By.XPATH, "//div[@class='current-price']/span[@class='price']") prices = [] for el in elements: price = el.text price = price.replace("zł", "") price = price.replace(",",".") price = price.rstrip() price = float(price) price = format(price,".2f") prices.append(price) numOfProducts = self.driver.find_elements(By.NAME, "product-quantity-spin") numsOfProducts = [] for num in numOfProducts: number = num.get_attribute("value") number = float(number) number = format(number,".2f") numsOfProducts.append(number) multiplyProducts = [] for i in range(0,len(prices)): multiply = float(numsOfProducts[i])*float(prices[i]) multiplyProducts.append(multiply) sumOfProducts = sum(multiplyProducts) sumOfProductss = format(sumOfProducts,".2f") sumNum = self.driver.find_element(By.XPATH, "//div[@id='cart-subtotal-products']/span[@class='value']").text.replace("zł","") sumNum = sumNum.replace(",",".") if float(sumOfProductss) == float(sumNum): result = True else: result = False return result def deleteFromCart(self): self.getFewProductsToCart(quantity=1) self.elementClick(locator=self._go_to_fulfill_the_order_button, locatorType="xpath") self.waitForElement(locator="cart-detailed-totals", locatorType="class") quantityOfProducts = self.driver.find_elements(By.XPATH, self._products_in_cart) quantity1 = len(quantityOfProducts) self.elementClick(locator=self._first_product_trashcan, locatorType="xpath") time.sleep(2) quantityOfProducts2 = self.driver.find_elements(By.XPATH, self._products_in_cart) quantity2 = len(quantityOfProducts2) if quantity1 > quantity2: result = True else: result = False return result def changeQuantity(self): self.getProductToCartPanda(quantity=2) self.elementClick(locator=self._go_to_fulfill_the_order_button, locatorType="xpath") self.waitForElement(locator="cart-detailed-totals", locatorType="class") firstPrice = self.driver.find_element(By.XPATH, "//div[@id='cart-subtotal-products']/span[@class='value']").text price1 = firstPrice.replace("zł", "") price1 = price1.replace(",",".") price1 = float(price1) price1 = format(price1, ".2f") self.elementClick(locator=self._touchspin_down, locatorType="xpath") time.sleep(2) secondPrice = self.driver.find_element(By.XPATH, "//div[@id='cart-subtotal-products']/span[@class='value']").text price2 = secondPrice.replace("zł", "") price2 = price2.replace(",",".").rstrip() price2 = float(price2) price2 = format(price2,".2f") if float(price1) > float(price2): result = True else: result = False return result
class ProductPage(BasePage): log = cl.customLogger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver self.nav = NavigationPage(driver) # Locators _product_title = "h1" #byclass _product_description = "product-description-short-30" #byId _size_S = '//div[@id="search_filters"]/section[2]/ul/li[1]//span[@class="custom-checkbox"]' _zoom_in_img = "material-icons zoom-in" #byClass _enlarge_img = "//div[@role='document']//figure/img" #byxpath width = 800 _img = "//div[@class='images-container']/div[1]/img" #byxpath _panda_tshirt = "//div[@id='js-product-list']/div[@class='products row']//a[contains(text(),'T-shirt Panda')]" # byXpath _product_availability = "product-availability" #byID _add_to_cart = "//form[@id='add-to-cart-or-refresh']//button[@type='submit']" def goToProductPage(self): self.nav.goToClothesPage() self.waitForElement(locator=self._panda_tshirt, locatorType="xpath") self.elementClick(locator=self._panda_tshirt, locatorType="xpath") self.waitForElement(locator=self._product_title, locatorType="class") def productTitle(self, title): self.goToProductPage() product = self.getElement(locator=self._product_title, locatorType="class") productTitle = product.text.lower() if title == productTitle: result = True else: result = False return result def productDescription(self, description): self.goToProductPage() productDescription = self.getElement( locator=self._product_description).text if description == productDescription: result = True else: result = False return result def imgDisplayed(self): self.goToProductPage() result = self.isElementDisplayed(locator=self._img, locatorType="xpath") return result def imgEnlarge(self): self.goToProductPage() self.elementClick(locator=self._zoom_in_img, locatorType="class") self.waitForElement(locator=self._enlarge_img, locatorType="xpath") img = self.getElement(locator=self._enlarge_img, locatorType="xpath") width = img.get_attribute("width") if width == "800": result = True else: result = False return result def sizeNotAvailable(self): self.goToProductPage() self.elementClick(locator=self._size_S, locatorType="xpath") self.waitForElement(locator=self._product_availability) availability = self.isElementDisplayed( locator=self._product_availability) addToCart = self.getElement(locator=self._add_to_cart, locatorType="xpath") addToCartStatus = addToCart.is_enabled() if (addToCartStatus == False) and (availability == True): result = True else: result = False return result
class DiscountsPage(BasePage): log = cl.customLogger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver self.nav = NavigationPage(driver) self.lp = LoginPage(driver) #Loctors _discount_info_clothes_page = "//div[@class='products row']//span[@class='discount-percentage discount-product']" #byXpath _panda_tshirt = "//div[@id='js-product-list']/div[@class='products row']//a[contains(text(),'T-shirt Panda')]" #byXpath _discount_info_element = "//div[@class='product-prices']//span[@class='discount discount-percentage']" _panda_tshirt_current_price = "//section[@id='main']//div[@class='product-prices']/div[2]//span[1]" _panda_tshirt_regular_price = "//div[@class='product-prices']//span[@class='regular-price']" def priceCheck(self, discountnum): currentPrice = self.driver.find_element( By.XPATH, self._panda_tshirt_current_price).get_attribute("content") currentPrice = currentPrice.replace(",", ".") regularPrice = self.driver.find_element( By.XPATH, self._panda_tshirt_regular_price).text regularPrice = regularPrice.replace("zł", "") regularPrice = regularPrice.replace(",", ".") discount = float(regularPrice) * float(discountnum) if (float(regularPrice) - float(discount)) == float(currentPrice): return True return False def discountForLoggedInClientSuccessful(self, email, password, discountnum): self.lp.login(email, password) self.nav.goToClothesPage() self.waitForElement(locator=self._panda_tshirt, locatorType='xpath') self.elementClick(locator=self._panda_tshirt, locatorType='xpath') discountInfo = self.isElementPresent( locator=self._discount_info_element, locatorType='xpath') if discountInfo and self.priceCheck(discountnum): result = True else: result = False self.lp.logout() return result def discountForLoggedInClientFailed(self): self.nav.goToClothesPage() self.waitForElement(locator=self._panda_tshirt, locatorType='xpath') self.elementClick(locator=self._panda_tshirt, locatorType='xpath') result = self.isElementPresent(locator=self._discount_info_element, locatorType='xpath') return result def discountInfoOnClothesPageElements(self, email, password, elementNum): self.lp.login(email, password) self.nav.goToClothesPage() self.waitForElement( locator= "//div[@id='js-product-list']/div[@class='products row']/article[1]", locatorType='xpath') discountInfo = self.driver.find_elements( By.XPATH, self._discount_info_clothes_page) if len(discountInfo) == elementNum: result = True else: result = False self.lp.logout() return result