<repo_name>schurakov/selenium-page-object-exersice<file_sep>/pages/basket_page.py
from .base_page import BasePage
from .locators import BasketPageLocators


class BasketPage(BasePage):
    def should_not_be_product_in_basket(self):
        assert self.is_not_element_present(*BasketPageLocators.SOME_PRODUCT_IN_BASKET), \
            "Some product in basket, but should not be"

    def should_be_text_about_empty_basket(self):
        expected_text = "Your basket is empty. Continue shopping"
        actual_text = self.browser.find_element(*BasketPageLocators.EMPTY_BASKET_TEXT)
        assert actual_text.text == expected_text, f"Unexpected empty basket text: {actual_text.text}. Expected: {expected_text}"
<file_sep>/pages/locators.py
from selenium.webdriver.common.by import By


class MainPageLocators:
    LOGIN_LINK = (By.CSS_SELECTOR, "#login_link")


class LoginPageLocators:
    LOGIN_FORM = (By.CSS_SELECTOR, "#login_form")
    REGISTRATION_FORM = (By.CSS_SELECTOR, "#register_form")
    REGISTRATION_FORM_EMAIL = (By.CSS_SELECTOR, "[name='registration-email']")
    REGISTRATION_FORM_PASS = (By.CSS_SELECTOR, "[name='registration-password1']")
    REGISTRATION_FORM_CONFIRM_PASS = (By.CSS_SELECTOR, "[name='registration-password2']")
    LOGIN_FORM_EMAIL = (By.CSS_SELECTOR, "[name='login-username']")
    LOGIN_FORM_PASS = (By.CSS_SELECTOR, "[name='login-password']")
    REGISTRATION_SUBMIT_BUTTON = (By.CSS_SELECTOR, "[name='registration_submit']")


class ProductPageLocators:
    ADD_TO_BASKET_BUTTON = (By.CSS_SELECTOR, ".btn-add-to-basket")
    ADDED_TO_BASKET_ALERT = (By.CSS_SELECTOR, ".alert:first-child .alertinner ")
    BASKET_BLOCK_IN_RIGHT_CORNER = (By.CSS_SELECTOR, ".basket-mini")
    PRODUCT_MAIN_PRISE = (By.CSS_SELECTOR, ".product_main .price_color")
    PRODUCT_MAIN_NAME = (By.CSS_SELECTOR, ".product_main h1")


class BasePageLocators:
    LOGIN_LINK = (By.CSS_SELECTOR, "#login_link")
    LOGIN_LINK_INVALID = (By.CSS_SELECTOR, "#login_link_inc")
    BASKET_BUTTON = (By.CSS_SELECTOR, ".basket-mini .btn")
    USER_ICON = (By.CSS_SELECTOR, ".icon-user")


class BasketPageLocators:
    EMPTY_BASKET_TEXT = (By.CSS_SELECTOR, "[id='content_inner'] > p") # TODO: придумать селектор получше
    SOME_PRODUCT_IN_BASKET = (By.CSS_SELECTOR, ".basket-items")
<file_sep>/pytest.ini
[pytest]
markers =
    login_guest: guest go to login page
    need_review: test for review<file_sep>/pages/product_page.py
from .base_page import BasePage
from .locators import ProductPageLocators


class ProductPage(BasePage):
    def add_product_to_basket(self):
        add_to_basket_button = self.browser.find_element(*ProductPageLocators.ADD_TO_BASKET_BUTTON)
        add_to_basket_button.click()

    def should_be_correct_price_in_basket(self):
        expected_price = self.get_product_price()
        price_in_basket = self.browser.find_element(*ProductPageLocators.BASKET_BLOCK_IN_RIGHT_CORNER)
        assert expected_price in price_in_basket.text, "Unexpected price in basket"

    def should_be_correct_add_to_basket_notification(self):
        expected_notification = self.get_product_name() + " has been added to your basket."
        notification = self.browser.find_element(*ProductPageLocators.ADDED_TO_BASKET_ALERT)
        assert expected_notification == notification.text, "Unexpected product name in add to basket notification"

    def get_product_price(self):
        product_price = self.browser.find_element(*ProductPageLocators.PRODUCT_MAIN_PRISE)
        return product_price.text

    def get_product_name(self):
        product_name = self.browser.find_element(*ProductPageLocators.PRODUCT_MAIN_NAME)
        return product_name.text

    def should_not_be_success_message(self):
        assert self.is_not_element_present(*ProductPageLocators.ADDED_TO_BASKET_ALERT), \
            "Success message is presented, but should not be"

    def should_disappear_success_message(self):
        assert self.is_disappeared(*ProductPageLocators.ADDED_TO_BASKET_ALERT), \
            "Success message is not disappeared, but should be"
