Files
stepik-tests/Pages.py
2025-04-29 12:29:54 +04:00

80 lines
2.9 KiB
Python

from BaseApp import BasePage
from selenium.webdriver.common.by import By
class Locators:
LOCATOR_SEARCH_INPUT = (By.CLASS_NAME, "search-form__input")
LOCATOR_SEARCH_SUBMIT = (By.CLASS_NAME, "search-form__submit")
LOCATOR_SEARCH_ITEM = (By.CLASS_NAME, "course-cards__item")
LOCATOR_SEARCH_RESULT_MESSAGE = (By.CLASS_NAME, "catalog__search-results-message")
LOCATOR_LOGIN_EMAIL_INPUT = (By.ID, "id_login_email")
LOCATOR_LOGIN_PASSWORD_INPUT = (By.ID, "id_login_password")
LOCATOR_LOGIN_FORM = (By.ID, "login_form")
LOCATOR_LOGIN_FORM_MESSAGES_LIST = (By.CLASS_NAME, "sign-form__messages")
LOCATOR_LOGIN_FORM_MESSAGE = (By.TAG_NAME, "li")
LOCATOR_USER_PROFILE_TOGGLER = (By.CLASS_NAME, "navbar__profile-toggler")
LOCATOR_COURSE_PROMO_FAV_BUTTON = (
By.XPATH,
"/html/body/main/section[3]/div/div[2]/button",
)
class MainPage(BasePage):
def enter_word(self, word):
search_field = self.find_element(Locators.LOCATOR_SEARCH_INPUT)
search_field.click()
search_field.send_keys(word)
def click_on_the_search_button(self):
self.find_element(Locators.LOCATOR_SEARCH_SUBMIT, time=5).click()
def check_search_result_items(self):
return self.find_elements(Locators.LOCATOR_SEARCH_ITEM, time=5)
def check_search_result_message(self):
return self.find_element(Locators.LOCATOR_SEARCH_RESULT_MESSAGE, time=5)
def check_search_input_text(self):
return self.find_element(Locators.LOCATOR_SEARCH_INPUT).text
class LoginPage(BasePage):
def __init__(self, driver):
super().__init__(driver)
self.base_url = "https://stepik.org/catalog?auth=login"
def enter_email(self, text):
search_field = self.find_element(Locators.LOCATOR_LOGIN_EMAIL_INPUT)
search_field.click()
search_field.send_keys(text)
def enter_password(self, text):
search_field = self.find_element(Locators.LOCATOR_LOGIN_PASSWORD_INPUT)
search_field.click()
search_field.send_keys(text)
def submit_login_form(self):
self.find_element(Locators.LOCATOR_LOGIN_FORM).submit()
def check_login_messages(self):
return self.find_element(
Locators.LOCATOR_LOGIN_FORM_MESSAGES_LIST
).find_elements(*Locators.LOCATOR_LOGIN_FORM_MESSAGE)
def check_login_success(self):
return len(self.find_elements(Locators.LOCATOR_USER_PROFILE_TOGGLER)) == 1
class CoursePromoPage(BasePage):
def __init__(self, driver):
super().__init__(driver)
self.base_url = "https://stepik.org/course/58852/promo"
def click_button_favourite(self):
self.find_element(Locators.LOCATOR_COURSE_PROMO_FAV_BUTTON).click()
def check_course_is_favourite(self):
fav_button = self.find_element(Locators.LOCATOR_COURSE_PROMO_FAV_BUTTON)
return fav_button.get_attribute("data-toggled") is not None