From 1f43ea4e805e3f509ff80d64572eef730433e52b Mon Sep 17 00:00:00 2001 From: EvaV21 Date: Sat, 21 Feb 2026 13:30:07 +0300 Subject: [PATCH 1/2] Add tests --- .gitignore | 7 +++++ README.md | 61 +++++++++++++++++++++++++++++++++++++- config.py | 2 ++ conftest.py | 42 ++++++++++++++++++++++++++ generators.py | 9 ++++++ locators.py | 32 ++++++++++++++++++++ tests/test_constructor.py | 35 ++++++++++++++++++++++ tests/test_login.py | 38 ++++++++++++++++++++++++ tests/test_logout.py | 54 +++++++++++++++++++++++++++++++++ tests/test_navigation.py | 50 +++++++++++++++++++++++++++++++ tests/test_registration.py | 38 ++++++++++++++++++++++++ 11 files changed, 367 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 config.py create mode 100644 conftest.py create mode 100644 generators.py create mode 100644 locators.py create mode 100644 tests/test_constructor.py create mode 100644 tests/test_login.py create mode 100644 tests/test_logout.py create mode 100644 tests/test_navigation.py create mode 100644 tests/test_registration.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f1cb570 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +__pycache__/ +*.pyc +.pytest_cache/ +.venv/ +venv/ +.idea/ +.env \ No newline at end of file diff --git a/README.md b/README.md index 5aa61ea..8dde1a4 100644 --- a/README.md +++ b/README.md @@ -1 +1,60 @@ -# Sprint_5 +Проект содержит автотесты для сервиса Stellar Burgers +https://stellarburgers.education-services.ru/ + +Тестирование выполнено с использованием: +- Python +- Selenium +- Pytest +- Google Chrome +- Mozilla Firefox + +## Проверяемый функционал + +### Регистрация +- Успешная регистрация +- Ошибка при коротком пароле + +### Авторизация +- Вход через кнопку «Войти в аккаунт» +- Вход через кнопку «Личный кабинет» +- Вход через форму регистрации +- Вход через форму восстановления пароля + +### Навигация +- Переход в личный кабинет +- Переход из ЛК в конструктор +- Переход по логотипу + +### Выход +- Выход из аккаунта через кнопку «Выйти» + +### Конструктор +- Переключение вкладок: + - Булки + - Соусы + - Начинки +--- +## Структура проекта +Sprint_5/ +│-- tests/ +│ ├─ test_login.py +│ ├─ test_logout.py +│ ├─ test_registration.py +│ ├─ test_constructor.py +│ └─ test_navigation.py +│-- locators.py +│-- generators.py +│-- conftest.py +│-- config.py +│-- .gitignore +│-- README.md + +--- +## Генерация тестовых данных +Email генерируется автоматически в формате: +eva_test_17_XXX@yandex.ru +Пароль генерируется автоматически и содержит минимум 6 символов. +--- +## Запуск тестов +```bash +pytest -vSome changes diff --git a/config.py b/config.py new file mode 100644 index 0000000..b7d442e --- /dev/null +++ b/config.py @@ -0,0 +1,2 @@ +BASE_URL = "https://stellarburgers.education-services.ru/" + diff --git a/conftest.py b/conftest.py new file mode 100644 index 0000000..0e52574 --- /dev/null +++ b/conftest.py @@ -0,0 +1,42 @@ +import pytest +from selenium import webdriver +from selenium.webdriver.support.ui import WebDriverWait +from generators import generate_email, generate_password # импортируем твои функции генерации + +# Фикстура для браузера +@pytest.fixture(params=["chrome", "firefox"]) +def driver(request): + browser = request.param + if browser == "chrome": + driver = webdriver.Chrome() + elif browser == "firefox": + driver = webdriver.Firefox() + else: + raise ValueError(f"Unsupported browser: {browser}") + + driver.maximize_window() + yield driver + driver.quit() + +# Фикстура для WebDriverWait +@pytest.fixture +def wait(driver): + return WebDriverWait(driver, 10) + +# Фикстура с реальным email +@pytest.fixture +def test_email(): + return "EvaWunder@yandex.ru" + +# Фикстура с реальным паролем +@pytest.fixture +def test_password(): + return "parol123" + +@pytest.fixture +def random_email(): + return generate_email() + +@pytest.fixture +def random_password(): + return generate_password() diff --git a/generators.py b/generators.py new file mode 100644 index 0000000..0f24727 --- /dev/null +++ b/generators.py @@ -0,0 +1,9 @@ +import random + +def generate_email(): + number = random.randint(100, 999) + return f"eva_test_17_{number}@yandex.ru" + +def generate_password(): + number = random.randint(100000, 999999) + return f"pass{number}" \ No newline at end of file diff --git a/locators.py b/locators.py new file mode 100644 index 0000000..8ef5e66 --- /dev/null +++ b/locators.py @@ -0,0 +1,32 @@ +from selenium.webdriver.common.by import By + +class Locators: + # Главная страница + LOGIN_BUTTON_MAIN = (By.XPATH, "//button[text()='Войти в аккаунт']") + PERSONAL_ACCOUNT_BUTTON = (By.CSS_SELECTOR, "a[href='/account']") + + # Регистрация / Вход + REGISTER_LINK = (By.LINK_TEXT, "Зарегистрироваться") + FORGOT_PASSWORD_LINK = (By.LINK_TEXT, "Восстановить пароль") + + # Поля формы регистрации + REGISTER_NAME_INPUT = (By.XPATH, "(//input[@type='text'])[1]") # Имя + REGISTER_EMAIL_INPUT = (By.XPATH, "(//input[@type='text'])[2]") # Email + REGISTER_PASSWORD_INPUT = (By.NAME, "Пароль") + REGISTER_BUTTON = (By.XPATH, "//button[normalize-space()='Зарегистрироваться']") + + # Логин + LOGIN_EMAIL_INPUT = (By.XPATH, "//input[@type='text']") # Поле email на странице логина + LOGIN_PASSWORD_INPUT = (By.NAME, "Пароль") # Поле пароля на странице логина + LOGIN_BUTTON = (By.XPATH, "//button[normalize-space()='Войти']") # Кнопка "Войти" + + PASSWORD_ERROR = (By.XPATH, "//p[contains(text(),'Некорректный пароль')]") + + # Личный кабинет + PROFILE_HEADER = (By.CSS_SELECTOR, "div.profile-header") # Уникальный элемент ЛК + LOGOUT_BUTTON = (By.XPATH, "//button[contains(text(),'Выход')]") + + # Конструктор + BUNS_TAB = (By.XPATH, "//span[text()='Булки']") + SAUCES_TAB = (By.XPATH, "//span[text()='Соусы']") + FILLINGS_TAB = (By.XPATH, "//span[text()='Начинки']") \ No newline at end of file diff --git a/tests/test_constructor.py b/tests/test_constructor.py new file mode 100644 index 0000000..33eca87 --- /dev/null +++ b/tests/test_constructor.py @@ -0,0 +1,35 @@ +from selenium.webdriver.support import expected_conditions as EC +from locators import Locators + +BASE_URL = "https://stellarburgers.education-services.ru/" + +def click_tab(driver, wait, locator): + tab = wait.until(EC.element_to_be_clickable(locator)) + driver.execute_script("arguments[0].click();", tab) + return tab + +def test_switch_to_sauces(driver, wait): + driver.get(BASE_URL) + + tab = click_tab(driver, wait, Locators.SAUCES_TAB) + + parent = tab.find_element("xpath", "..") + assert "current" in parent.get_attribute("class") + + +def test_switch_to_fillings(driver, wait): + driver.get(BASE_URL) + + tab = click_tab(driver, wait, Locators.FILLINGS_TAB) + + parent = tab.find_element("xpath", "..") + assert "current" in parent.get_attribute("class") + + +def test_switch_to_buns(driver, wait): + driver.get(BASE_URL) + + tab = click_tab(driver, wait, Locators.BUNS_TAB) + + parent = tab.find_element("xpath", "..") + assert "current" in parent.get_attribute("class") \ No newline at end of file diff --git a/tests/test_login.py b/tests/test_login.py new file mode 100644 index 0000000..97fccd8 --- /dev/null +++ b/tests/test_login.py @@ -0,0 +1,38 @@ +import pytest +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.common.by import By +from locators import Locators + +TEST_EMAIL = "EvaWunder@yandex.ru" +TEST_PASSWORD = "parol123" + +def login(driver, wait, email, password): + + email_input = wait.until(EC.visibility_of_element_located(Locators.LOGIN_EMAIL_INPUT)) + email_input.clear() + email_input.send_keys(email) + + password_input = wait.until(EC.visibility_of_element_located(Locators.LOGIN_PASSWORD_INPUT)) + password_input.clear() + password_input.send_keys(password) + + login_btn = wait.until(EC.element_to_be_clickable(Locators.LOGIN_BUTTON)) + login_btn.click() + +@pytest.mark.parametrize("driver_name", ["chrome", "firefox"]) +def test_login_spa(driver, wait, driver_name): + driver.get("https://stellarburgers.education-services.ru/") + + + main_login_btn = wait.until(EC.element_to_be_clickable(Locators.LOGIN_BUTTON_MAIN)) + main_login_btn.click() + + login(driver, wait, TEST_EMAIL, TEST_PASSWORD) + + order_button = wait.until( + EC.text_to_be_present_in_element( + (By.CSS_SELECTOR, "button.button_button__33qZ0.button_button_type_primary__1O7Bx.button_button_size_large__G21Vg"), + "Оформить заказ" + ) + ) + assert order_button, "Пользователь не авторизован после логина: кнопка не изменилась" \ No newline at end of file diff --git a/tests/test_logout.py b/tests/test_logout.py new file mode 100644 index 0000000..8fdb9b8 --- /dev/null +++ b/tests/test_logout.py @@ -0,0 +1,54 @@ +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.common.by import By +from locators import Locators + +BASE_URL = "https://stellarburgers.education-services.ru/" + +TEST_EMAIL = "EvaWunder@yandex.ru" +TEST_PASSWORD = "parol123" + + +def login(driver, wait): + email_input = wait.until( + EC.visibility_of_element_located(Locators.LOGIN_EMAIL_INPUT) + ) + email_input.clear() + email_input.send_keys(TEST_EMAIL) + + password_input = wait.until( + EC.visibility_of_element_located(Locators.LOGIN_PASSWORD_INPUT) + ) + password_input.clear() + password_input.send_keys(TEST_PASSWORD) + + login_btn = wait.until( + EC.element_to_be_clickable(Locators.LOGIN_BUTTON) + ) + login_btn.click() + + wait.until(EC.url_to_be(BASE_URL)) + + +def test_logout(driver, wait): + driver.get(BASE_URL) + + wait.until( + EC.element_to_be_clickable(Locators.LOGIN_BUTTON_MAIN) + ).click() + + login(driver, wait) + + account_btn = wait.until( + EC.element_to_be_clickable(Locators.PERSONAL_ACCOUNT_BUTTON) + ) + driver.execute_script("arguments[0].click();", account_btn) + + wait.until(EC.url_contains("/account")) + + logout_btn = wait.until( + EC.visibility_of_element_located(Locators.LOGOUT_BUTTON) + ) + driver.execute_script("arguments[0].click();", logout_btn) + + wait.until(EC.url_contains("login")) + assert "login" in driver.current_url \ No newline at end of file diff --git a/tests/test_navigation.py b/tests/test_navigation.py new file mode 100644 index 0000000..ee66a94 --- /dev/null +++ b/tests/test_navigation.py @@ -0,0 +1,50 @@ +import pytest +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.common.by import By + +from locators import Locators +from config import BASE_URL + +OVERLAY = (By.CSS_SELECTOR, "div.Modal_modal_overlay__x2ZCr") + + +def login(driver, wait, test_email, test_password): + email_input = wait.until( + EC.visibility_of_element_located(Locators.LOGIN_EMAIL_INPUT) + ) + email_input.clear() + email_input.send_keys(test_email) + + password_input = wait.until( + EC.visibility_of_element_located(Locators.LOGIN_PASSWORD_INPUT) + ) + password_input.clear() + password_input.send_keys(test_password) + + login_btn = wait.until( + EC.element_to_be_clickable(Locators.LOGIN_BUTTON) + ) + login_btn.click() + + wait.until(EC.url_to_be(BASE_URL)) + + +def test_go_to_personal_account(driver, wait, test_email, test_password): + driver.get(BASE_URL) + + wait.until( + EC.element_to_be_clickable(Locators.LOGIN_BUTTON_MAIN) + ).click() + + login(driver, wait, test_email, test_password) + + wait.until(EC.invisibility_of_element_located(OVERLAY)) + + account_btn = wait.until( + EC.element_to_be_clickable(Locators.PERSONAL_ACCOUNT_BUTTON) + ) + driver.execute_script("arguments[0].click();", account_btn) + + wait.until(EC.url_contains("/account")) + + assert "/account" in driver.current_url \ No newline at end of file diff --git a/tests/test_registration.py b/tests/test_registration.py new file mode 100644 index 0000000..2c27e46 --- /dev/null +++ b/tests/test_registration.py @@ -0,0 +1,38 @@ +import pytest +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.common.by import By +from locators import Locators +from config import BASE_URL + +def login(driver, wait, email, password): + email_input = wait.until(EC.visibility_of_element_located(Locators.LOGIN_EMAIL_INPUT)) + email_input.clear() + email_input.send_keys(email) + + password_input = wait.until(EC.visibility_of_element_located(Locators.LOGIN_PASSWORD_INPUT)) + password_input.clear() + password_input.send_keys(password) + + login_btn = wait.until(EC.element_to_be_clickable(Locators.LOGIN_BUTTON)) + login_btn.click() + + wait.until(EC.visibility_of_element_located(Locators.PERSONAL_ACCOUNT_BUTTON)) + + +def test_register_user(driver, wait, random_email, random_password): + driver.get(BASE_URL) + + wait.until(EC.element_to_be_clickable(Locators.PERSONAL_ACCOUNT_BUTTON)).click() + + wait.until(EC.element_to_be_clickable(Locators.REGISTER_LINK)).click() + + wait.until(EC.visibility_of_element_located(Locators.REGISTER_NAME_INPUT)).send_keys("Eva Test") + wait.until(EC.visibility_of_element_located(Locators.REGISTER_EMAIL_INPUT)).send_keys(random_email) + wait.until(EC.visibility_of_element_located(Locators.REGISTER_PASSWORD_INPUT)).send_keys(random_password) + + wait.until(EC.element_to_be_clickable(Locators.REGISTER_BUTTON)).click() + + login_button = wait.until(EC.visibility_of_element_located(Locators.LOGIN_BUTTON)) + assert login_button.is_displayed(), "Кнопка 'Войти' не появилась после регистрации" + + From 4d4e8e9dfd8eff19e60fab5483e76f086d39c69f Mon Sep 17 00:00:00 2001 From: EvaV21 Date: Sun, 22 Feb 2026 17:56:54 +0300 Subject: [PATCH 2/2] Refactor tests, move test data to data.py, update README --- README.md | 32 ++++++------- conftest.py | 59 ++++++++++++++++------- data.py | 2 + generators.py | 9 ---- locators.py | 30 ++++++++---- tests/test_constructor.py | 44 ++++++++--------- tests/test_login.py | 96 +++++++++++++++++++++++++++----------- tests/test_logout.py | 54 ++++----------------- tests/test_navigation.py | 73 ++++++++++++++++------------- tests/test_registration.py | 84 ++++++++++++++++++++++++--------- 10 files changed, 280 insertions(+), 203 deletions(-) create mode 100644 data.py delete mode 100644 generators.py diff --git a/README.md b/README.md index 8dde1a4..0ee34c2 100644 --- a/README.md +++ b/README.md @@ -1,41 +1,40 @@ -Проект содержит автотесты для сервиса Stellar Burgers +# Sprint_5 — автотесты Stellar Burgers + +Проект содержит автотесты для сервиса Stellar Burgers: https://stellarburgers.education-services.ru/ Тестирование выполнено с использованием: - Python - Selenium - Pytest -- Google Chrome -- Mozilla Firefox +- Google Chrome / Mozilla Firefox ## Проверяемый функционал - ### Регистрация - Успешная регистрация - Ошибка при коротком пароле ### Авторизация -- Вход через кнопку «Войти в аккаунт» +- Вход через кнопку «Войти в аккаунт» на главной странице - Вход через кнопку «Личный кабинет» -- Вход через форму регистрации -- Вход через форму восстановления пароля +- Вход через кнопку в форме регистрации +- Вход через кнопку в форме восстановления пароля ### Навигация - Переход в личный кабинет -- Переход из ЛК в конструктор -- Переход по логотипу +- Переход из личного кабинета в конструктор (по кнопке «Конструктор») +- Переход в конструктор по клику на логотип Stellar Burgers ### Выход -- Выход из аккаунта через кнопку «Выйти» +- Выход из аккаунта через кнопку «Выйти» в личном кабинете ### Конструктор - Переключение вкладок: - Булки - Соусы - Начинки ---- + ## Структура проекта -Sprint_5/ │-- tests/ │ ├─ test_login.py │ ├─ test_logout.py @@ -43,18 +42,13 @@ Sprint_5/ │ ├─ test_constructor.py │ └─ test_navigation.py │-- locators.py -│-- generators.py │-- conftest.py │-- config.py +│-- data.py │-- .gitignore │-- README.md ---- ## Генерация тестовых данных Email генерируется автоматически в формате: -eva_test_17_XXX@yandex.ru +`eva_test_17_XXX@yandex.ru` Пароль генерируется автоматически и содержит минимум 6 символов. ---- -## Запуск тестов -```bash -pytest -vSome changes diff --git a/conftest.py b/conftest.py index 0e52574..269cc18 100644 --- a/conftest.py +++ b/conftest.py @@ -1,42 +1,65 @@ import pytest +import random from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait -from generators import generate_email, generate_password # импортируем твои функции генерации +from selenium.webdriver.support import expected_conditions as EC -# Фикстура для браузера -@pytest.fixture(params=["chrome", "firefox"]) +from config import BASE_URL +from locators import Locators +from data import TEST_EMAIL, TEST_PASSWORD + + +def pytest_addoption(parser): + parser.addoption( + "--browser", + action="store", + default="chrome", + help="Choose browser: chrome or firefox" + ) + + +@pytest.fixture def driver(request): - browser = request.param + browser = request.config.getoption("--browser") + if browser == "chrome": driver = webdriver.Chrome() elif browser == "firefox": driver = webdriver.Firefox() else: - raise ValueError(f"Unsupported browser: {browser}") + raise ValueError("Browser not supported") driver.maximize_window() yield driver driver.quit() -# Фикстура для WebDriverWait + @pytest.fixture def wait(driver): return WebDriverWait(driver, 10) -# Фикстура с реальным email -@pytest.fixture -def test_email(): - return "EvaWunder@yandex.ru" -# Фикстура с реальным паролем @pytest.fixture -def test_password(): - return "parol123" +def authorized_user(driver, wait): + driver.get(BASE_URL) -@pytest.fixture -def random_email(): - return generate_email() + wait.until(EC.element_to_be_clickable(Locators.LOGIN_BUTTON_MAIN)).click() + + wait.until(EC.visibility_of_element_located( + Locators.LOGIN_EMAIL_INPUT)).send_keys(TEST_EMAIL) + + wait.until(EC.visibility_of_element_located( + Locators.LOGIN_PASSWORD_INPUT)).send_keys(TEST_PASSWORD) + + wait.until(EC.element_to_be_clickable( + Locators.LOGIN_BUTTON)).click() + + wait.until(EC.url_to_be(BASE_URL)) + return driver @pytest.fixture -def random_password(): - return generate_password() +def random_user(): + number = random.randint(100, 999) + email = f"eva_test_17_{number}@yandex.ru" + password = f"Pass{random.randint(100000, 999999)}" + return email, password \ No newline at end of file diff --git a/data.py b/data.py new file mode 100644 index 0000000..fa6f899 --- /dev/null +++ b/data.py @@ -0,0 +1,2 @@ +TEST_EMAIL = "EvaWunder@yandex.ru" +TEST_PASSWORD = "parol123" \ No newline at end of file diff --git a/generators.py b/generators.py deleted file mode 100644 index 0f24727..0000000 --- a/generators.py +++ /dev/null @@ -1,9 +0,0 @@ -import random - -def generate_email(): - number = random.randint(100, 999) - return f"eva_test_17_{number}@yandex.ru" - -def generate_password(): - number = random.randint(100000, 999999) - return f"pass{number}" \ No newline at end of file diff --git a/locators.py b/locators.py index 8ef5e66..2a67461 100644 --- a/locators.py +++ b/locators.py @@ -1,32 +1,42 @@ from selenium.webdriver.common.by import By + class Locators: # Главная страница LOGIN_BUTTON_MAIN = (By.XPATH, "//button[text()='Войти в аккаунт']") PERSONAL_ACCOUNT_BUTTON = (By.CSS_SELECTOR, "a[href='/account']") - + LOGO = (By.CSS_SELECTOR, "div.AppHeader_header__logo__2D0X2 a") + CONSTRUCTOR_BUTTON = (By.XPATH, "//p[text()='Конструктор']") + # Регистрация / Вход REGISTER_LINK = (By.LINK_TEXT, "Зарегистрироваться") FORGOT_PASSWORD_LINK = (By.LINK_TEXT, "Восстановить пароль") - - # Поля формы регистрации - REGISTER_NAME_INPUT = (By.XPATH, "(//input[@type='text'])[1]") # Имя - REGISTER_EMAIL_INPUT = (By.XPATH, "(//input[@type='text'])[2]") # Email + # Внутри формы регистрации + LOGIN_LINK_IN_REGISTER = (By.LINK_TEXT, "Войти") + + # Внутри формы восстановления + LOGIN_LINK_IN_FORGOT = (By.LINK_TEXT, "Войти") + + # Поля регистрации + REGISTER_NAME_INPUT = (By.XPATH, "(//input[@type='text'])[1]") + REGISTER_EMAIL_INPUT = (By.XPATH, "(//input[@type='text'])[2]") REGISTER_PASSWORD_INPUT = (By.NAME, "Пароль") REGISTER_BUTTON = (By.XPATH, "//button[normalize-space()='Зарегистрироваться']") # Логин - LOGIN_EMAIL_INPUT = (By.XPATH, "//input[@type='text']") # Поле email на странице логина - LOGIN_PASSWORD_INPUT = (By.NAME, "Пароль") # Поле пароля на странице логина - LOGIN_BUTTON = (By.XPATH, "//button[normalize-space()='Войти']") # Кнопка "Войти" + LOGIN_EMAIL_INPUT = (By.XPATH, "//input[@type='text']") + LOGIN_PASSWORD_INPUT = (By.NAME, "Пароль") + LOGIN_BUTTON = (By.XPATH, "//button[normalize-space()='Войти']") PASSWORD_ERROR = (By.XPATH, "//p[contains(text(),'Некорректный пароль')]") # Личный кабинет - PROFILE_HEADER = (By.CSS_SELECTOR, "div.profile-header") # Уникальный элемент ЛК LOGOUT_BUTTON = (By.XPATH, "//button[contains(text(),'Выход')]") # Конструктор BUNS_TAB = (By.XPATH, "//span[text()='Булки']") SAUCES_TAB = (By.XPATH, "//span[text()='Соусы']") - FILLINGS_TAB = (By.XPATH, "//span[text()='Начинки']") \ No newline at end of file + FILLINGS_TAB = (By.XPATH, "//span[text()='Начинки']") + + # Overlay + MODAL_OVERLAY = (By.CSS_SELECTOR, "div.Modal_modal_overlay__x2ZCr") \ No newline at end of file diff --git a/tests/test_constructor.py b/tests/test_constructor.py index 33eca87..ccd2b92 100644 --- a/tests/test_constructor.py +++ b/tests/test_constructor.py @@ -1,35 +1,37 @@ from selenium.webdriver.support import expected_conditions as EC from locators import Locators +from config import BASE_URL -BASE_URL = "https://stellarburgers.education-services.ru/" -def click_tab(driver, wait, locator): - tab = wait.until(EC.element_to_be_clickable(locator)) - driver.execute_script("arguments[0].click();", tab) - return tab +class TestConstructor: -def test_switch_to_sauces(driver, wait): - driver.get(BASE_URL) + def click_tab(self, driver, wait, locator): + tab = wait.until(EC.element_to_be_clickable(locator)) + driver.execute_script("arguments[0].click();", tab) + return tab - tab = click_tab(driver, wait, Locators.SAUCES_TAB) + def test_switch_to_sauces(self, driver, wait): + driver.get(BASE_URL) - parent = tab.find_element("xpath", "..") - assert "current" in parent.get_attribute("class") + tab = self.click_tab(driver, wait, Locators.SAUCES_TAB) + parent = tab.find_element("xpath", "..") + assert "current" in parent.get_attribute("class") -def test_switch_to_fillings(driver, wait): - driver.get(BASE_URL) + def test_switch_to_fillings(self, driver, wait): + driver.get(BASE_URL) - tab = click_tab(driver, wait, Locators.FILLINGS_TAB) + tab = self.click_tab(driver, wait, Locators.FILLINGS_TAB) + parent = tab.find_element("xpath", "..") - parent = tab.find_element("xpath", "..") - assert "current" in parent.get_attribute("class") + assert "current" in parent.get_attribute("class") + def test_switch_to_buns(self, driver, wait): + driver.get(BASE_URL) + + self.click_tab(driver, wait, Locators.SAUCES_TAB) -def test_switch_to_buns(driver, wait): - driver.get(BASE_URL) + tab = self.click_tab(driver, wait, Locators.BUNS_TAB) + parent = tab.find_element("xpath", "..") - tab = click_tab(driver, wait, Locators.BUNS_TAB) - - parent = tab.find_element("xpath", "..") - assert "current" in parent.get_attribute("class") \ No newline at end of file + assert "current" in parent.get_attribute("class") \ No newline at end of file diff --git a/tests/test_login.py b/tests/test_login.py index 97fccd8..d21f288 100644 --- a/tests/test_login.py +++ b/tests/test_login.py @@ -1,38 +1,80 @@ -import pytest from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from locators import Locators +from config import BASE_URL +from data import TEST_EMAIL, TEST_PASSWORD -TEST_EMAIL = "EvaWunder@yandex.ru" -TEST_PASSWORD = "parol123" -def login(driver, wait, email, password): - - email_input = wait.until(EC.visibility_of_element_located(Locators.LOGIN_EMAIL_INPUT)) - email_input.clear() - email_input.send_keys(email) +class TestLogin: - password_input = wait.until(EC.visibility_of_element_located(Locators.LOGIN_PASSWORD_INPUT)) - password_input.clear() - password_input.send_keys(password) + def login(self, driver, wait): + wait.until( + EC.visibility_of_element_located(Locators.LOGIN_EMAIL_INPUT) + ).send_keys(TEST_EMAIL) - login_btn = wait.until(EC.element_to_be_clickable(Locators.LOGIN_BUTTON)) - login_btn.click() + wait.until( + EC.visibility_of_element_located(Locators.LOGIN_PASSWORD_INPUT) + ).send_keys(TEST_PASSWORD) -@pytest.mark.parametrize("driver_name", ["chrome", "firefox"]) -def test_login_spa(driver, wait, driver_name): - driver.get("https://stellarburgers.education-services.ru/") + wait.until( + EC.element_to_be_clickable(Locators.LOGIN_BUTTON) + ).click() - - main_login_btn = wait.until(EC.element_to_be_clickable(Locators.LOGIN_BUTTON_MAIN)) - main_login_btn.click() + wait.until( + EC.text_to_be_present_in_element( + (By.XPATH, "//button[contains(text(),'Оформить заказ')]"), + "Оформить заказ" + ) + ) - login(driver, wait, TEST_EMAIL, TEST_PASSWORD) + def test_login_from_main_button(self, driver, wait): + driver.get(BASE_URL) - order_button = wait.until( - EC.text_to_be_present_in_element( - (By.CSS_SELECTOR, "button.button_button__33qZ0.button_button_type_primary__1O7Bx.button_button_size_large__G21Vg"), - "Оформить заказ" - ) - ) - assert order_button, "Пользователь не авторизован после логина: кнопка не изменилась" \ No newline at end of file + wait.until( + EC.element_to_be_clickable(Locators.LOGIN_BUTTON_MAIN) + ).click() + + self.login(driver, wait) + + def test_login_from_personal_account(self, driver, wait): + driver.get(BASE_URL) + + wait.until( + EC.element_to_be_clickable(Locators.PERSONAL_ACCOUNT_BUTTON) + ).click() + + self.login(driver, wait) + + def test_login_from_forgot_password(self, driver, wait): + driver.get(BASE_URL) + + wait.until( + EC.element_to_be_clickable(Locators.PERSONAL_ACCOUNT_BUTTON) + ).click() + + wait.until( + EC.element_to_be_clickable(Locators.FORGOT_PASSWORD_LINK) + ).click() + + wait.until( + EC.element_to_be_clickable(Locators.LOGIN_LINK_IN_FORGOT) + ).click() + + self.login(driver, wait) + + def test_login_from_registration_form(self, driver, wait): + driver.get(BASE_URL) + + wait.until( + EC.element_to_be_clickable(Locators.PERSONAL_ACCOUNT_BUTTON) + ).click() + + wait.until( + EC.element_to_be_clickable(Locators.REGISTER_LINK) + ).click() + + wait.until( + EC.element_to_be_clickable(Locators.LOGIN_LINK_IN_REGISTER) + ).click() + + self.login(driver, wait) \ No newline at end of file diff --git a/tests/test_logout.py b/tests/test_logout.py index 8fdb9b8..1a59b60 100644 --- a/tests/test_logout.py +++ b/tests/test_logout.py @@ -1,54 +1,20 @@ from selenium.webdriver.support import expected_conditions as EC -from selenium.webdriver.common.by import By from locators import Locators -BASE_URL = "https://stellarburgers.education-services.ru/" -TEST_EMAIL = "EvaWunder@yandex.ru" -TEST_PASSWORD = "parol123" +class TestLogout: + def test_logout(self, authorized_user, wait): + driver = authorized_user -def login(driver, wait): - email_input = wait.until( - EC.visibility_of_element_located(Locators.LOGIN_EMAIL_INPUT) - ) - email_input.clear() - email_input.send_keys(TEST_EMAIL) + wait.until(EC.element_to_be_clickable( + Locators.PERSONAL_ACCOUNT_BUTTON)).click() - password_input = wait.until( - EC.visibility_of_element_located(Locators.LOGIN_PASSWORD_INPUT) - ) - password_input.clear() - password_input.send_keys(TEST_PASSWORD) + wait.until(EC.url_contains("/account")) - login_btn = wait.until( - EC.element_to_be_clickable(Locators.LOGIN_BUTTON) - ) - login_btn.click() + wait.until(EC.element_to_be_clickable( + Locators.LOGOUT_BUTTON)).click() - wait.until(EC.url_to_be(BASE_URL)) + wait.until(EC.url_contains("login")) - -def test_logout(driver, wait): - driver.get(BASE_URL) - - wait.until( - EC.element_to_be_clickable(Locators.LOGIN_BUTTON_MAIN) - ).click() - - login(driver, wait) - - account_btn = wait.until( - EC.element_to_be_clickable(Locators.PERSONAL_ACCOUNT_BUTTON) - ) - driver.execute_script("arguments[0].click();", account_btn) - - wait.until(EC.url_contains("/account")) - - logout_btn = wait.until( - EC.visibility_of_element_located(Locators.LOGOUT_BUTTON) - ) - driver.execute_script("arguments[0].click();", logout_btn) - - wait.until(EC.url_contains("login")) - assert "login" in driver.current_url \ No newline at end of file + assert "login" in driver.current_url \ No newline at end of file diff --git a/tests/test_navigation.py b/tests/test_navigation.py index ee66a94..8cfaa9a 100644 --- a/tests/test_navigation.py +++ b/tests/test_navigation.py @@ -1,50 +1,57 @@ -import pytest from selenium.webdriver.support import expected_conditions as EC -from selenium.webdriver.common.by import By - from locators import Locators from config import BASE_URL -OVERLAY = (By.CSS_SELECTOR, "div.Modal_modal_overlay__x2ZCr") +class TestNavigation: + + def test_go_to_personal_account(self, authorized_user, wait): + driver = authorized_user + + wait.until( + EC.invisibility_of_element_located(Locators.MODAL_OVERLAY) + ) + + wait.until( + EC.element_to_be_clickable(Locators.PERSONAL_ACCOUNT_BUTTON) + ).click() + + wait.until(EC.url_contains("/account")) + + assert "/account" in driver.current_url + + + def test_go_to_constructor_via_button(self, authorized_user, wait): + driver = authorized_user -def login(driver, wait, test_email, test_password): - email_input = wait.until( - EC.visibility_of_element_located(Locators.LOGIN_EMAIL_INPUT) - ) - email_input.clear() - email_input.send_keys(test_email) + wait.until( + EC.element_to_be_clickable(Locators.PERSONAL_ACCOUNT_BUTTON) + ).click() - password_input = wait.until( - EC.visibility_of_element_located(Locators.LOGIN_PASSWORD_INPUT) - ) - password_input.clear() - password_input.send_keys(test_password) + wait.until(EC.url_contains("/account")) - login_btn = wait.until( - EC.element_to_be_clickable(Locators.LOGIN_BUTTON) - ) - login_btn.click() + wait.until( + EC.element_to_be_clickable(Locators.CONSTRUCTOR_BUTTON) + ).click() - wait.until(EC.url_to_be(BASE_URL)) + wait.until(EC.url_to_be(BASE_URL)) + assert driver.current_url == BASE_URL -def test_go_to_personal_account(driver, wait, test_email, test_password): - driver.get(BASE_URL) - wait.until( - EC.element_to_be_clickable(Locators.LOGIN_BUTTON_MAIN) - ).click() + def test_go_to_constructor_via_logo(self, authorized_user, wait): + driver = authorized_user - login(driver, wait, test_email, test_password) + wait.until( + EC.element_to_be_clickable(Locators.PERSONAL_ACCOUNT_BUTTON) + ).click() - wait.until(EC.invisibility_of_element_located(OVERLAY)) + wait.until(EC.url_contains("/account")) - account_btn = wait.until( - EC.element_to_be_clickable(Locators.PERSONAL_ACCOUNT_BUTTON) - ) - driver.execute_script("arguments[0].click();", account_btn) + wait.until( + EC.element_to_be_clickable(Locators.LOGO) + ).click() - wait.until(EC.url_contains("/account")) + wait.until(EC.url_to_be(BASE_URL)) - assert "/account" in driver.current_url \ No newline at end of file + assert driver.current_url == BASE_URL \ No newline at end of file diff --git a/tests/test_registration.py b/tests/test_registration.py index 2c27e46..25bdc3d 100644 --- a/tests/test_registration.py +++ b/tests/test_registration.py @@ -1,38 +1,78 @@ -import pytest from selenium.webdriver.support import expected_conditions as EC -from selenium.webdriver.common.by import By from locators import Locators from config import BASE_URL +import pytest +import random + + +class TestRegistration: + + def test_register_user(self, driver, wait, random_user): + email, password = random_user + + driver.get(BASE_URL) + + wait.until( + EC.element_to_be_clickable(Locators.PERSONAL_ACCOUNT_BUTTON) + ).click() + + wait.until( + EC.element_to_be_clickable(Locators.REGISTER_LINK) + ).click() + + wait.until( + EC.visibility_of_element_located(Locators.REGISTER_NAME_INPUT) + ).send_keys("Eva Test") + + wait.until( + EC.visibility_of_element_located(Locators.REGISTER_EMAIL_INPUT) + ).send_keys(email) + + wait.until( + EC.visibility_of_element_located(Locators.REGISTER_PASSWORD_INPUT) + ).send_keys(password) -def login(driver, wait, email, password): - email_input = wait.until(EC.visibility_of_element_located(Locators.LOGIN_EMAIL_INPUT)) - email_input.clear() - email_input.send_keys(email) + wait.until( + EC.element_to_be_clickable(Locators.REGISTER_BUTTON) + ).click() - password_input = wait.until(EC.visibility_of_element_located(Locators.LOGIN_PASSWORD_INPUT)) - password_input.clear() - password_input.send_keys(password) + login_button = wait.until( + EC.visibility_of_element_located(Locators.LOGIN_BUTTON) + ) - login_btn = wait.until(EC.element_to_be_clickable(Locators.LOGIN_BUTTON)) - login_btn.click() + assert login_button.is_displayed() - wait.until(EC.visibility_of_element_located(Locators.PERSONAL_ACCOUNT_BUTTON)) + def test_register_with_invalid_password(self, driver, wait, random_user): + email, _ = random_user + driver.get(BASE_URL) -def test_register_user(driver, wait, random_email, random_password): - driver.get(BASE_URL) + wait.until( + EC.element_to_be_clickable(Locators.PERSONAL_ACCOUNT_BUTTON) + ).click() - wait.until(EC.element_to_be_clickable(Locators.PERSONAL_ACCOUNT_BUTTON)).click() + wait.until( + EC.element_to_be_clickable(Locators.REGISTER_LINK) + ).click() - wait.until(EC.element_to_be_clickable(Locators.REGISTER_LINK)).click() + wait.until( + EC.visibility_of_element_located(Locators.REGISTER_NAME_INPUT) + ).send_keys("Eva Test") - wait.until(EC.visibility_of_element_located(Locators.REGISTER_NAME_INPUT)).send_keys("Eva Test") - wait.until(EC.visibility_of_element_located(Locators.REGISTER_EMAIL_INPUT)).send_keys(random_email) - wait.until(EC.visibility_of_element_located(Locators.REGISTER_PASSWORD_INPUT)).send_keys(random_password) + wait.until( + EC.visibility_of_element_located(Locators.REGISTER_EMAIL_INPUT) + ).send_keys(email) - wait.until(EC.element_to_be_clickable(Locators.REGISTER_BUTTON)).click() + wait.until( + EC.visibility_of_element_located(Locators.REGISTER_PASSWORD_INPUT) + ).send_keys("123") - login_button = wait.until(EC.visibility_of_element_located(Locators.LOGIN_BUTTON)) - assert login_button.is_displayed(), "Кнопка 'Войти' не появилась после регистрации" + wait.until( + EC.element_to_be_clickable(Locators.REGISTER_BUTTON) + ).click() + error = wait.until( + EC.visibility_of_element_located(Locators.PASSWORD_ERROR) + ) + assert error.is_displayed() \ No newline at end of file