From e70e5124d44a2ee7edfa199ffb4e83c6fcbccbab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=9F=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=BF=D0=BE=D0=B2?= Date: Tue, 29 Apr 2025 12:29:54 +0400 Subject: [PATCH] done --- .env.example | 2 ++ Pages.py | 12 ++++++++---- Tests.py | 46 +++++++++++++++++++++++++++++++++++++--------- poetry.lock | 31 ++++++++++++++++++++++++++++++- pyproject.toml | 3 ++- 5 files changed, 79 insertions(+), 15 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..d9f837b --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +STEPIK_LOGIN=user@example.com +STEPIK_PASSWORD=password diff --git a/Pages.py b/Pages.py index 1497d58..acb8503 100644 --- a/Pages.py +++ b/Pages.py @@ -1,12 +1,9 @@ from BaseApp import BasePage from selenium.webdriver.common.by import By -from selenium.webdriver.common.action_chains import ActionChains - -from conftest import browser class Locators: - LOCATOR_SEARCH_INPUT = (By.CLASS_NAME, "search-form__input ") + 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") @@ -15,6 +12,7 @@ class Locators: 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", @@ -37,6 +35,9 @@ class MainPage(BasePage): 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): @@ -61,6 +62,9 @@ class LoginPage(BasePage): 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): diff --git a/Tests.py b/Tests.py index 5569a51..063d8e5 100644 --- a/Tests.py +++ b/Tests.py @@ -1,13 +1,21 @@ +import os from Pages import LoginPage, MainPage, CoursePromoPage +import dotenv + +dotenv.load_dotenv() + +STEPIK_LOGIN = os.getenv("STEPIK_LOGIN") +STEPIK_PASSWORD = os.getenv("STEPIK_PASSWORD") def test_positive_courses_search(browser): page = MainPage(browser) page.go_to_site() - page.enter_word("математика") + q = "математика" + page.enter_word(q) page.click_on_the_search_button() items = page.check_search_result_items() - assert len(items) > 0 + assert len(items) > 0, f'Курсы по запросу "{q}" не найдены' def test_negative_courses_search(browser): @@ -23,7 +31,24 @@ def test_negative_courses_search(browser): + "» ничего не найдено.\n" + "Попробуйте изменить параметры поиска." in search_result_message.text - ) + ), f'По запросу "{search_phrase}" были найдены курсы' + + +def test_add_course_to_favourite(browser): + page = CoursePromoPage(browser) + page.go_to_site() + assert not page.check_course_is_favourite(), "Курс изначально в избранном" + page.click_button_favourite() + assert page.check_course_is_favourite(), "Курс не добавился в избранное" + + +def test_search_form_input_persist(browser): + page = MainPage(browser) + page.go_to_site() + q = "математика" + page.enter_word(q) + page.driver.refresh() + assert q == page.check_search_input_text(), "Текст в поле поиска не сохранился" def test_negative_login(browser): @@ -33,12 +58,15 @@ def test_negative_login(browser): page.enter_password("password") page.submit_login_form() messages = page.check_login_messages() - assert messages[0].text == "E-mail адрес и/или пароль не верны." + assert ( + messages[0].text == "E-mail адрес и/или пароль не верны." + ), "Неверный вывод ошибки авторизации" -def test_add_course_to_favourite(browser): - page = CoursePromoPage(browser) +def test_positive_login(browser): + page = LoginPage(browser) page.go_to_site() - assert not page.check_course_is_favourite() - page.click_button_favourite() - assert page.check_course_is_favourite() + page.enter_email(STEPIK_LOGIN) + page.enter_password(STEPIK_PASSWORD) + page.submit_login_form() + assert page.check_login_success(), "Ошибка авторизации" diff --git a/poetry.lock b/poetry.lock index e0af323..b3c0782 100644 --- a/poetry.lock +++ b/poetry.lock @@ -126,6 +126,20 @@ files = [ {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, ] +[[package]] +name = "dotenv" +version = "0.9.9" +description = "Deprecated package" +optional = false +python-versions = "*" +groups = ["main"] +files = [ + {file = "dotenv-0.9.9-py2.py3-none-any.whl", hash = "sha256:29cf74a087b31dafdb5a446b6d7e11cbce8ed2741540e2339c69fbef92c94ce9"}, +] + +[package.dependencies] +python-dotenv = "*" + [[package]] name = "h11" version = "0.16.0" @@ -255,6 +269,21 @@ pluggy = ">=1.5,<2" [package.extras] dev = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] +[[package]] +name = "python-dotenv" +version = "1.1.0" +description = "Read key-value pairs from a .env file and set them as environment variables" +optional = false +python-versions = ">=3.9" +groups = ["main"] +files = [ + {file = "python_dotenv-1.1.0-py3-none-any.whl", hash = "sha256:d7c01d9e2293916c18baf562d95698754b0dbbb5e74d457c45d4f6561fb9d55d"}, + {file = "python_dotenv-1.1.0.tar.gz", hash = "sha256:41f90bc6f5f177fb41f53e87666db362025010eb28f60a01c9143bfa33a2b2d5"}, +] + +[package.extras] +cli = ["click (>=5.0)"] + [[package]] name = "selenium" version = "4.31.0" @@ -404,4 +433,4 @@ h11 = ">=0.9.0,<1" [metadata] lock-version = "2.1" python-versions = ">=3.12" -content-hash = "1fa059942d855f68d8a148c3154737e9f2e128a9366b3064579dd8b38b46581a" +content-hash = "2f20f9de987d3a34220e105428639975a582acce8dc59a105356a1689d2a4169" diff --git a/pyproject.toml b/pyproject.toml index 5a3f35d..ea412ef 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,8 @@ readme = "README.md" requires-python = ">=3.12" dependencies = [ "pytest (>=8.3.5,<9.0.0)", - "selenium (>=4.31.0,<5.0.0)" + "selenium (>=4.31.0,<5.0.0)", + "dotenv (>=0.9.9,<0.10.0)" ] [tool.poetry]