Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing the code structure #48

Merged
merged 12 commits into from
May 13, 2024
81 changes: 0 additions & 81 deletions pages/basket_page.py

This file was deleted.

71 changes: 71 additions & 0 deletions pages/checkout_cart_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import time
import allure
import pytest
from selene import browser, be, have
# from selene.support.conditions.have import css_property
# from selene.core.query import css_property
from selene.support.shared.jquery_style import s, ss
# from selenium.webdriver import Keys
from pages.locators import ProductLocators as PL
from selenium.webdriver.support.color import Color

"================Функции OLD VERSION ПРЕНЕСЕНЫ для правильного выполнения тестов в mini_cart.py===================="


# class BasketPage(BasePage):
@pytest.mark.skip
def check_color_and_clickability_of_view_and_edit_cart_link_in_the_mini_cart():
""" old version"""
time.sleep(1)
s(PL.MINI_BASKET_WINDOW).click()
edit = s(PL.VIEW_AND_EDIT_CART_HREF)
edit.should(have.attribute("href"))
s('a.action').should(have.css_property("color", Color.from_string("#006bb4").rgba))
# color = browser.element(PL.VIEW_AND_EDIT_CART_HREF).value_of_css_property("color")
# color = browser.element(PL.VIEW_AND_EDIT_CART_HREF).should(have(css_property("color")))

# color = s(PL.VIEW_AND_EDIT_CART_HREF).get("color")
# color.should(have(css_property("color")))
# s(should_have(css_property, expected_value)


@pytest.mark.skip # Пробный тест, находили способ проверить цвет элемента
def check_color_button():
""" old version"""
s(PL.MINI_BASKET_WINDOW).click()
s('a.action').should(have.css_property("color", Color.from_string("#006bb4").rgba))

# login_button_colour = Color.from_string(browser.find_element(By.CSS_SELECTOR, 'login').value_of_css_property('color')).rgba

# assert login_button_background_colour.hex == '#ff69b4'
# assert login_button_background_colour.rgba == 'rgba(255, 105, 180, 1)'
# assert login_button_background_colour.rgb == 'rgb(255, 105, 180)'

# login_button_colour = Color.from_string(driver.find_element(By.ID, 'login').value_of_css_property('color'))
# login_button_background_colour = Color.from_string(driver.find_element(By.ID, 'login').value_of_css_property('background-color'))


@allure.link("https://trello.com/c/lvLslLGD")
def checking_product_name_are_correct_in_checkout_cart_page():
s(PL.NAME_ARGUS_ALL_WEATHER_TANK_CHECKOUT_CART).should(have.text("Argus All-Weather Tank"))


def checking_size_are_correct_in_checkout_cart_page():
s(PL.SIZE_M_ARGUS_ALL_WEATHER_TANK_CHECKOUT_CART).should(have.text("M"))


def checking_color_are_correct_in_checkout_cart_page():
s(PL.COLOR_GRAY_ARGUS_CHECKOUT_CART).should(have.text("Gray"))


@allure.link("https://trello.com/c/SQ3op4DX")
def check_price_present_in_checkout_cart_page():
s(PL.PRICE_ITEM_CHECKOUT_CART).should(be.present).should(have.text("$22.00"))


def check_qty_present_in_checkout_cart_page():
s(PL.QTY_FIELD_CHECKOUT_CART).should(be.present)


def check_subtotal_present_in_checkout_cart_page():
s(PL.CART_SUBTOTAL_CHECKOUT_CART).should(be.present).should(have.text("$"))
17 changes: 15 additions & 2 deletions pages/home_page.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from selene.support.shared.jquery_style import s, ss

from selene import be
from pages.base_page import BasePage
from pages.locators import NavigatorLocators as NL
# from pages.basket_page import BasketPage
from pages.locators import NavigatorLocators as NL, ProductLocators as PL
from pages.urls import main_page_link


class HomePage(BasePage):
Expand All @@ -16,3 +18,14 @@ def go_to_pages(self):

def navigate_to(self, locator):
s(locator).click()

def add_to_cart_from_main_page(self):
s(PL.ARGUS_All_WEATHER_TANK_SIZE).click()
s(PL.ARGUS_All_WEATHER_TANK_COLOR).click()
s(PL.ARGUS_All_WEATHER_TANK_ADD_TO_CARD).click()

def go_to_mini_cart(self):
s(PL.MINI_BASKET_WINDOW).should(be.clickable).click()

def go_to_checkout_cart(self):
s(PL.VIEW_AND_EDIT_CART_LINK).click()
8 changes: 8 additions & 0 deletions pages/locators.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ class ProductLocators:
SHOULD_CHOOSE_SIZE_AND_COLOR = '.swatch-input super-attribute-select'
TEXT_REQUIRED_FIELD = 'This is a required field.'

NAME_ARGUS_ALL_WEATHER_TANK_CHECKOUT_CART = '//*[@id="shopping-cart-table"] //*[text()="Argus All-Weather Tank"]'
SIZE_M_ARGUS_ALL_WEATHER_TANK_CHECKOUT_CART = '// *[contains(text(), "M")]/../..// *[ @ id = "shopping-cart-table"]'
COLOR_GRAY_ARGUS_CHECKOUT_CART = '//*[@id="shopping-cart-table"]//*[contains(text(),"Gray")]'
PRICE_ITEM_CHECKOUT_CART = '//*[@class="col price"] //*[text()="$22.00"]'
CART_SUBTOTAL_CHECKOUT_CART = '//*[@class="col subtotal"] //*[text()="$22.00"]'
QTY_FIELD_CHECKOUT_CART = '[class="field qty"] input'


class HomeLocators:
STORE_LOGO = 'a.logo'

Expand Down
48 changes: 48 additions & 0 deletions pages/mini_cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,57 @@

from selene import browser, be, have
from selene.support.shared.jquery_style import s, ss
from selenium.webdriver import Keys

from pages.locators import ProductLocators as PL
from selenium.webdriver.support.color import Color


def checkout():
time.sleep(3)
s('.viewcart').should(be.clickable)
s('#top-cart-btn-checkout').should(be.clickable).click()


def check_color_of_view_and_edit_cart_link_in_the_mini_cart():
s('a.action').should(have.css_property("color", Color.from_string("#006bb4").rgba))


def check_clickability_of_view_and_edit_cart_link_in_the_mini_cart():
edit = s(PL.VIEW_AND_EDIT_CART_HREF)
edit.should(have.attribute("href"))


def checking_the_link_opens_checkout_cart_page():
s(PL.VIEW_AND_EDIT_CART_LINK).click()


def checking_the_size_color_and_product_name_are_correct():
s(PL.SEE_DETAILS).click()
s(PL.SIZE_M).should(have.text("M"))
s(PL.COLOR_GRAY).should(have.text("Gray"))
s(PL.NAME_ITEM).should(have.text("Argus All-Weather Tank"))


def checking_present_price_item_and_cart_subtotal_in_the_mini_cart():
s(PL.PRICE_ITEM).should(have.text("$22.00"))
s(PL.CART_SUBTOTAL).should(have.text("$22.00"))


def change_qty():
s(PL.QTY_FIELD).should(be.clickable).send_keys(Keys.BACKSPACE + "7")
s(PL.UPDATE).click()


def should_be_quantity_change():
s(PL.QTY_FIELD).should(have.value("7"))
time.sleep(2)


def should_be_success_message():
s(".message-success").should(be.visible)


def should_be_change_subtotal():
s(PL.PRICE_ITEM).should(have.text("$22.00"))
s(PL.CART_SUBTOTAL).should(have.text("$154.00"))
1 change: 1 addition & 0 deletions pages/urls.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
main_page_link = "https://magento.softwaretestingboard.com"
checkout_cart = "https://magento.softwaretestingboard.com/checkout/cart/"
32 changes: 27 additions & 5 deletions tests/test_checkout.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import time

import allure
import pytest
import selene
from selene.support.shared.jquery_style import s, ss
from selene import browser, be, have
from pages import mini_cart, checkout_shipping
from pages import mini_cart, checkout_shipping, checkout_cart_page
from pages.locators import ProductLocators as PL
from pages.product_page import ProductPage
from pages.user import Person
from selene.support.conditions import *
from selene.support import by

from pages.urls import *
from pages.home_page import HomePage

@pytest.mark.skip
def test_checkout_from_mini_cart():
Expand All @@ -35,5 +36,26 @@ def test_checkout_from_mini_cart():
browser.should(have.url_containing('success'))




@allure.link("https://trello.com/c/lvLslLGD")
def test_size_color_and_product_name_are_correct_in_the_checkout_cart_page_tc_005_001_016():
page = HomePage(browser, main_page_link)
page.open()
page.add_to_cart_from_main_page()
time.sleep(2)
page.go_to_mini_cart()
page.go_to_checkout_cart()
checkout_cart_page.checking_product_name_are_correct_in_checkout_cart_page()
checkout_cart_page.checking_size_are_correct_in_checkout_cart_page()
checkout_cart_page.checking_color_are_correct_in_checkout_cart_page()

@allure.link("https://trello.com/c/SQ3op4DX")
def test_check_price_qty_and_cart_subtotal_present_in_checkout_cart_page_tc_005_001_017():
page = HomePage(browser, main_page_link)
page.open()
page.add_to_cart_from_main_page()
time.sleep(2)
page.go_to_mini_cart()
page.go_to_checkout_cart()
checkout_cart_page.check_price_present_in_checkout_cart_page()
checkout_cart_page.check_subtotal_present_in_checkout_cart_page()
checkout_cart_page.check_qty_present_in_checkout_cart_page()
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import time
import allure
from selene import browser
from pages.basket_page import BasketPage
from pages.urls import main_page_link
from pages import mini_cart
from pages.home_page import HomePage
from pages.urls import *


# тестов мало поэтому нет необходимости выносить это в фикстуру
Expand All @@ -17,17 +19,20 @@

@allure.link('https://trello.com/c/WVaLK93g')
def test_add_to_cart_from_main():
page = BasketPage(browser, main_page_link)
page = HomePage(browser, main_page_link)
page.open()
page.add_to_cart_from_main_page()


@allure.link('https://trello.com/c/WVaLK93g')
def test_color_and_clickability_of_view_and_edit_cart_link_in_the_mini_cart_tc_005_001_011():
page = BasketPage(browser, main_page_link)
page = HomePage(browser, main_page_link)
page.open()
page.check_color_and_clickability_of_view_and_edit_cart_link_in_the_mini_cart()
# time.sleep(5)
page.add_to_cart_from_main_page()
time.sleep(2)
page.go_to_mini_cart()
# mini_cart = BasketPage(browser, main_page_link)
mini_cart.check_color_of_view_and_edit_cart_link_in_the_mini_cart()
mini_cart.check_clickability_of_view_and_edit_cart_link_in_the_mini_cart()


# @pytest.mark.skip # пробный искали цвет
Expand All @@ -39,27 +44,42 @@ def test_color_and_clickability_of_view_and_edit_cart_link_in_the_mini_cart_tc_0

@allure.link('https://trello.com/c/w8Of4GYe')
def test_checking_the_link_opens_the_cart_page_tc_005_001_012():
page = BasketPage(browser, main_page_link)
page = HomePage(browser, main_page_link)
page.open()
page.checking_the_link_opens_the_cart_page()
page.add_to_cart_from_main_page()
time.sleep(2)
page.go_to_mini_cart()
mini_cart.checking_the_link_opens_checkout_cart_page()


@allure.link("https://trello.com/c/v4hVrwzq")
def test_size_color_and_product_name_are_correct_tc_005_001_013():
page = BasketPage(browser, main_page_link)
page = HomePage(browser, main_page_link)
page.open()
page.checking_the_size_color_and_product_name_are_correct()
page.add_to_cart_from_main_page()
time.sleep(2)
page.go_to_mini_cart()
mini_cart.checking_the_size_color_and_product_name_are_correct()


@allure.link("https://trello.com/c/p6iExP1c")
def test_checking_present_price_item_and_cart_subtotal_in_the_mini_cart_tc_005_001_014():
page = BasketPage(browser, main_page_link)
page = HomePage(browser, main_page_link)
page.open()
page.checking_present_price_item_and_cart_subtotal_in_the_mini_cart()
page.add_to_cart_from_main_page()
time.sleep(2)
page.go_to_mini_cart()
mini_cart.checking_present_price_item_and_cart_subtotal_in_the_mini_cart()


@allure.link("https://trello.com/c/uCZZgQks")
def test_change_quantity_of_an_item_and_changes_price_in_cart_subtotal_mini_cart_tc_005_001_015():
page = BasketPage(browser, main_page_link)
page = HomePage(browser, main_page_link)
page.open()
page.change_quantity_of_an_item_and_changes_price_in_cart_subtotal_mini_cart()
page.add_to_cart_from_main_page()
time.sleep(2)
page.go_to_mini_cart()
mini_cart.should_be_success_message()
mini_cart.change_qty()
mini_cart.should_be_quantity_change()
mini_cart.should_be_change_subtotal()
Loading