Skip to content

Conversation

@Alexey3234
Copy link
Owner

No description provided.

confest.py Outdated
Comment on lines 13 to 16
@pytest.fixture
def base_url():
"""Базовый URL тестируемого приложения"""
return "https://stellarburgers.nomoreparties.site/"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: фикстуры не занимаются выполнением примитивной логики, они выполняют сложную логику предусловий\постусловий и вычислений. Эти объекты можно сразу создавать в тестах

confest.py Outdated
Comment on lines 13 to 16
@pytest.fixture
def base_url():
"""Базовый URL тестируемого приложения"""
return "https://stellarburgers.nomoreparties.site/"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно лучше: адреса лучше вынести во внешний модуль(например, urls). Они могут измениться, что затруднит поддержку тестов

class TestConstructorNavigation:
def test_buns_section(self, driver, base_url):
driver.get(base_url)
time.sleep(2)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: использование sleep не допускается. Стоит посмотреть в сторону нативных expected conditions в selenium

driver.get(base_url)
time.sleep(2)

driver.find_element(By.XPATH, "//span[text()='Соусы']").click()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: все локаторы следует хранить в отдельном модуле locators. Так мы сможем их переиспользовать в других местах и не править каждый при изменениях на странице

Comment on lines 6 to 37
def test_buns_section(self, driver, base_url):
driver.get(base_url)
time.sleep(2)

driver.find_element(By.XPATH, "//span[text()='Соусы']").click()
time.sleep(1)

driver.find_element(By.XPATH, "//span[text()='Булки']").click()
time.sleep(1)

active_tab = driver.find_element(By.CSS_SELECTOR, ".tab_tab__1SPyG.tab_tab_type_current__2BEPc")
assert "Булки" in active_tab.text, "Раздел 'Булки' не активирован"

def test_sauces_section(self, driver, base_url):
driver.get(base_url)
time.sleep(2)

driver.find_element(By.XPATH, "//span[text()='Соусы']").click()
time.sleep(1)

active_tab = driver.find_element(By.CSS_SELECTOR, ".tab_tab__1SPyG.tab_tab_type_current__2BEPc")
assert "Соусы" in active_tab.text, "Раздел 'Соусы' не активирован"

def test_toppings_section(self, driver, base_url):
driver.get(base_url)
time.sleep(2)

driver.find_element(By.XPATH, "//span[text()='Начинки']").click()
time.sleep(1)

active_tab = driver.find_element(By.CSS_SELECTOR, ".tab_tab__1SPyG.tab_tab_type_current__2BEPc")
assert "Начинки" in active_tab.text, "Раздел 'Начинки' не активирован" No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно лучше: шаги этих тестов схожи. Можно их объединить с помощью параметризации

test_logout.py Outdated
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

def test_logout_from_account(driver, base_url, test_credentials):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить здесь и далее: Для корректного запуска тестов необходимо код с шагами теста поместить в тестовый метод (нейминг начинается с test_), а метод - в тестовый класс (нейминг начинается с Test). Необходимо привести к такому формату все модули внутри пакета tests

test_logout.py Outdated
from selenium.webdriver.support import expected_conditions as EC

def test_logout_from_account(driver, base_url, test_credentials):
try:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Необходимо исправить: не стоит использовать в теле теста try-except конструкцию. Если цель - сделать скриншот при падении, то стоит это делать на уровне фикстуры/хука

Comment on lines 6 to 15
def login(self, driver, base_url, test_credentials):
driver.get(f"{base_url}login")
time.sleep(2)

driver.find_element(By.XPATH, "//input[@name='name']").send_keys(test_credentials["email"])
driver.find_element(By.XPATH, "//input[@type='password']").send_keys(test_credentials["password"])
time.sleep(1)

driver.find_element(By.XPATH, "//button[text()='Войти']").click()
time.sleep(2)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Необходимо исправить: в модуле с тестами должны быть только тесты. Фикстуры стоит вынести в модуль conftest, а вспомогательные методы - в helpers

submit_button = driver.find_element(By.XPATH, "//button[text()='Зарегистрироваться']")
submit_button.click()

WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//h2[text()='Вход']")))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Необходимо исправить: тест должен заканчиваться проверкой

Comment on lines 21 to 23
name_input = driver.find_element(By.XPATH, "//fieldset[1]//input")
email_input = driver.find_element(By.XPATH, "//fieldset[2]//input")
password_input = driver.find_element(By.XPATH, "//fieldset[3]//input")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Необходимо исправить здесь и далее: не стоит использовать в локаторах путь от рута, абсолютный путь или индексы элемента. Это делает локатор очень хрупким

conftest.py Outdated
Comment on lines 111 to 113
@pytest.fixture
def base_url():
return BASE_URL No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: фикстуры не занимаются выполнением примитивной логики, они выполняют сложную логику предусловий\постусловий и вычислений. Эти объекты можно сразу создавать в тестах

helpers.py Outdated

def login(driver, base_url, test_credentials):
driver.get(f"{base_url}login")
time.sleep(2)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: лучше обойтись без time.sleep и посмотреть в сторону явных ожиданий selenium`а (expected conditions)

).click()

# Финальная проверка активной вкладки "Булки"
WebDriverWait(driver, 10).until(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Необходимо исправить: этот тест ничего не проверяет. Стоит использовать assert-инструкцию

test_login.py Outdated
Comment on lines 10 to 27
def perform_login(self, driver, email, password):
"""Вспомогательный метод для выполнения входа"""
email_field = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, "//input[@name='name']"))
)
email_field.clear()
email_field.send_keys(email)

password_field = driver.find_element(By.XPATH, "//input[@type='password']")
password_field.clear()
password_field.send_keys(password)

login_button = driver.find_element(By.XPATH, "//button[text()='Войти']")
login_button.click()

WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, "//button[text()='Оформить заказ']"))
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Необходимо исправить: в модуле с тестами должны быть только тесты. Фикстуры стоит вынести в модуль conftest, а вспомогательные методы - в helpers

test_login.py Outdated
def test_login_from_main_page_button(self, driver, registered_user):
"""Тест входа через кнопку на главной странице"""
driver.get(BASE_URL)
driver.find_element(By.XPATH, "//button[text()='Войти в аккаунт']").click()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: все локаторы следует хранить в отдельном модуле locators. Так мы сможем их переиспользовать в других местах и не править каждый при изменениях на странице

test_login.py Outdated
def test_login_from_personal_account_button(self, driver, registered_user):
"""Тест входа через кнопку личного кабинета"""
driver.get(BASE_URL)
driver.find_element(By.XPATH, "//a[@href='/account']").click()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: все локаторы следует хранить в отдельном модуле locators. Так мы сможем их переиспользовать в других местах и не править каждый при изменениях на странице

test_login.py Outdated
def test_login_from_registration_form(self, driver, registered_user):
"""Тест входа через форму регистрации"""
driver.get(f"{BASE_URL}register")
driver.find_element(By.XPATH, "//a[text()='Войти']").click()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: все локаторы следует хранить в отдельном модуле locators. Так мы сможем их переиспользовать в других местах и не править каждый при изменениях на странице

test_login.py Outdated
def test_login_from_forgot_password_form(self, driver, registered_user):
"""Тест входа через форму восстановления пароля"""
driver.get(f"{BASE_URL}forgot-password")
driver.find_element(By.XPATH, "//a[text()='Войти']").click()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: все локаторы следует хранить в отдельном модуле locators. Так мы сможем их переиспользовать в других местах и не править каждый при изменениях на странице

Comment on lines 11 to 19
@pytest.fixture
def temp_credentials(self):
"""Генерация уникальных учетных данных для теста"""
timestamp = int(time.time() * 1000)
return {
"name": f"User{timestamp}",
"email": f"user{timestamp}@example.com",
"password": f"Pass{timestamp % 10000}"
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Необходимо исправить: в модуле с тестами должны быть только тесты. Фикстуры стоит вынести в модуль conftest, а вспомогательные методы - в helpers. Этот метод больше выглядит как функция генерации данных, которую стоит вынести в helpers

…могательные методы в helpers,убрал фикстуры с простой логикой, откорректировал тесты без time.sleep
Comment on lines +56 to +58
WebDriverWait(driver, 10).until(
EC.visibility_of_element_located(ConstructorPageLocators.BUNS_SECTION)
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Необходимо исправить: этот тест ничего не проверяет, необходимо воспользоваться assert-инструкцией

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants