-
Notifications
You must be signed in to change notification settings - Fork 0
Sprint 5 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Sprint 5 #1
Conversation
confest.py
Outdated
| @pytest.fixture | ||
| def base_url(): | ||
| """Базовый URL тестируемого приложения""" | ||
| return "https://stellarburgers.nomoreparties.site/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нужно исправить: фикстуры не занимаются выполнением примитивной логики, они выполняют сложную логику предусловий\постусловий и вычислений. Эти объекты можно сразу создавать в тестах
confest.py
Outdated
| @pytest.fixture | ||
| def base_url(): | ||
| """Базовый URL тестируемого приложения""" | ||
| return "https://stellarburgers.nomoreparties.site/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно лучше: адреса лучше вынести во внешний модуль(например, urls). Они могут измениться, что затруднит поддержку тестов
test_constructor.py
Outdated
| class TestConstructorNavigation: | ||
| def test_buns_section(self, driver, base_url): | ||
| driver.get(base_url) | ||
| time.sleep(2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нужно исправить: использование sleep не допускается. Стоит посмотреть в сторону нативных expected conditions в selenium
test_constructor.py
Outdated
| driver.get(base_url) | ||
| time.sleep(2) | ||
|
|
||
| driver.find_element(By.XPATH, "//span[text()='Соусы']").click() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нужно исправить: все локаторы следует хранить в отдельном модуле locators. Так мы сможем их переиспользовать в других местах и не править каждый при изменениях на странице
test_constructor.py
Outdated
| 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 |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Необходимо исправить: не стоит использовать в теле теста try-except конструкцию. Если цель - сделать скриншот при падении, то стоит это делать на уровне фикстуры/хука
test_navigation.py
Outdated
| 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Необходимо исправить: в модуле с тестами должны быть только тесты. Фикстуры стоит вынести в модуль conftest, а вспомогательные методы - в helpers
test_registration.py
Outdated
| 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()='Вход']"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Необходимо исправить: тест должен заканчиваться проверкой
test_registration.py
Outdated
| 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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Необходимо исправить здесь и далее: не стоит использовать в локаторах путь от рута, абсолютный путь или индексы элемента. Это делает локатор очень хрупким
conftest.py
Outdated
| @pytest.fixture | ||
| def base_url(): | ||
| return BASE_URL No newline at end of file |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)
test_constructor.py
Outdated
| ).click() | ||
|
|
||
| # Финальная проверка активной вкладки "Булки" | ||
| WebDriverWait(driver, 10).until( |
There was a problem hiding this comment.
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
| 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()='Оформить заказ']")) | ||
| ) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нужно исправить: все локаторы следует хранить в отдельном модуле locators. Так мы сможем их переиспользовать в других местах и не править каждый при изменениях на странице
test_registration.py
Outdated
| @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}" | ||
| } |
There was a problem hiding this comment.
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
| WebDriverWait(driver, 10).until( | ||
| EC.visibility_of_element_located(ConstructorPageLocators.BUNS_SECTION) | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Необходимо исправить: этот тест ничего не проверяет, необходимо воспользоваться assert-инструкцией
No description provided.