generated from yandex-praktikum/qa_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Sprint_5 #4
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
Open
JaneM00
wants to merge
1
commit into
main
Choose a base branch
from
Sprint_5
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Sprint_5 #4
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| # tests.py | ||
|
|
||
| import time | ||
| import unittest | ||
| from selenium import webdriver | ||
| from selenium.webdriver.common.by import By | ||
| from selenium.webdriver.support.ui import WebDriverWait | ||
| from selenium.webdriver.support import expected_conditions as EC | ||
| from locators import * | ||
|
|
||
| class StellarBurgersTests(unittest.TestCase): | ||
|
|
||
| def setUp(self): | ||
| options = webdriver.ChromeOptions() | ||
| options.add_argument('headless') | ||
| self.driver = webdriver.Chrome(options=options) | ||
| self.wait = WebDriverWait(self.driver, 10) | ||
|
|
||
| def tearDown(self): | ||
| self.driver.quit() | ||
|
|
||
| # Тест успешной регистрации | ||
| def test_successful_registration(self): | ||
| self.driver.get(MAIN_PAGE_URL) | ||
| self.driver.find_element(By.XPATH, REGISTER_BUTTON_MAIN_PAGE).click() | ||
| wait.until(EC.visibility_of_element_located((By.XPATH, REGISTRATION_FORM_NAME_INPUT))) | ||
|
|
||
| # Заполняем форму регистрации | ||
| self.driver.find_element(By.XPATH, REGISTRATION_FORM_NAME_INPUT).send_keys('John Doe') | ||
| self.driver.find_element(By.XPATH, REGISTRATION_FORM_EMAIL_INPUT).send_keys('johndoe@example.com') | ||
| self.driver.find_element(By.XPATH, REGISTRATION_FORM_PASSWORD_INPUT).send_keys('123456') | ||
| self.driver.find_element(By.XPATH, REGISTRATION_FORM_SUBMIT_BUTTON).click() | ||
|
|
||
| # Проверяем успешность регистрации | ||
| self.wait.until(EC.visibility_of_element_located((By.XPATH, PERSONAL_ACCOUNT_LINK))) | ||
| personal_account_text = self.driver.find_element(By.XPATH, PERSONAL_ACCOUNT_LINK).text | ||
| self.assertEqual(personal_account_text, 'Личный кабинет') | ||
|
|
||
| # Тест ошибки при вводе короткого пароля | ||
| def test_short_password_error(self): | ||
| self.driver.get(MAIN_PAGE_URL) | ||
| self.driver.find_element(By.XPATH, REGISTER_BUTTON_MAIN_PAGE).click() | ||
| wait.until(EC.visibility_of_element_located((By.XPATH, REGISTRATION_FORM_NAME_INPUT))) | ||
|
|
||
| # Заполняем форму регистрации с коротким паролем | ||
| self.driver.find_element(By.XPATH, REGISTRATION_FORM_NAME_INPUT).send_keys('John Doe') | ||
| self.driver.find_element(By.XPATH, REGISTRATION_FORM_EMAIL_INPUT).send_keys('johndoe@example.com') | ||
| self.driver.find_element(By.XPATH, REGISTRATION_FORM_PASSWORD_INPUT).send_keys('12345') # Пароль короче минимального | ||
| self.driver.find_element(By.XPATH, REGISTRATION_FORM_SUBMIT_BUTTON).click() | ||
|
|
||
| # Проверяем наличие ошибки | ||
| error_message = self.driver.find_element(By.CLASS_NAME, 'error').text | ||
| self.assertIn('Пароль должен содержать минимум 6 символов', error_message) | ||
|
|
||
| # Тест входа по кнопке "Войти в аккаунт" на главной странице | ||
| def test_login_via_main_page_button(self): | ||
| self.driver.get(MAIN_PAGE_URL) | ||
| self.driver.find_element(By.XPATH, LOGIN_BUTTON_MAIN_PAGE).click() | ||
| wait.until(EC.visibility_of_element_located((By.XPATH, LOGIN_FORM_EMAIL_INPUT))) | ||
|
|
||
| # Заполняем форму входа | ||
| self.driver.find_element(By.XPATH, LOGIN_FORM_EMAIL_INPUT).send_keys('existing_user@example.com') | ||
| self.driver.find_element(By.XPATH, LOGIN_FORM_PASSWORD_INPUT).send_keys('valid_password') | ||
| self.driver.find_element(By.XPATH, LOGIN_FORM_SUBMIT_BUTTON).click() | ||
|
|
||
| # Проверяем успешность входа | ||
| self.wait.until(EC.visibility_of_element_located((By.XPATH, PERSONAL_ACCOUNT_LINK))) | ||
| personal_account_text = self.driver.find_element(By.XPATH, PERSONAL_ACCOUNT_LINK).text | ||
| self.assertEqual(personal_account_text, 'Личный кабинет') | ||
|
|
||
| # Тест перехода в личный кабинет по клику на ссылку | ||
| def test_personal_account_link_click(self): | ||
| self.driver.get(MAIN_PAGE_URL) | ||
| self.driver.find_element(By.XPATH, PERSONAL_ACCOUNT_LINK).click() | ||
| self.wait.until(EC.url_contains('/account')) | ||
|
|
||
| # Тест выхода из аккаунта | ||
| def test_logout(self): | ||
| self.driver.get(MAIN_PAGE_URL) | ||
| self.driver.find_element(By.XPATH, LOGIN_BUTTON_MAIN_PAGE).click() | ||
| wait.until(EC.visibility_of_element_located((By.XPATH, LOGIN_FORM_EMAIL_INPUT))) | ||
|
|
||
| # Вход в аккаунт | ||
| self.driver.find_element(By.XPATH, LOGIN_FORM_EMAIL_INPUT).send_keys('existing_user@example.com') | ||
| self.driver.find_element(By.XPATH, LOGIN_FORM_PASSWORD_INPUT).send_keys('valid_password') | ||
| self.driver.find_element(By.XPATH, LOGIN_FORM_SUBMIT_BUTTON).click() | ||
|
|
||
| # Переходим в личный кабинет | ||
| self.wait.until(EC.visibility_of_element_located((By.XPATH, PERSONAL_ACCOUNT_LINK))) | ||
| self.driver.find_element(By.XPATH, PERSONAL_ACCOUNT_LINK).click() | ||
|
|
||
| # Нажимаем кнопку выхода | ||
| self.driver.find_element(By.XPATH, PERSONAL_ACCOUNT_LOGOUT_BUTTON).click() | ||
|
|
||
| # Проверяем успешность выхода | ||
| self.wait.until(EC.visibility_of_element_located((By.XPATH, LOGIN_BUTTON_MAIN_PAGE))) | ||
| login_button_text = self.driver.find_element(By.XPATH, LOGIN_BUTTON_MAIN_PAGE).text | ||
| self.assertEqual(login_button_text, 'Войти') | ||
|
|
||
| # Тест открытия раздела "Булки" в конструкторе | ||
| def test_open_buns_section(self): | ||
| self.driver.get(MAIN_PAGE_URL) | ||
| self.driver.find_element(By.XPATH, BURGER_LOGO).click() | ||
| self.wait.until(EC.visibility_of_element_located((By.XPATH, CONSTRUCTOR_BUNS_SECTION))) | ||
| buns_section_visible = self.driver.find_element(By.XPATH, CONSTRUCTOR_BUNS_SECTION).is_displayed() | ||
| self.assertTrue(buns_section_visible) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Нужно исправить: тесты должны быть разделены на модули по функциональности, в модулях - содержатся тестовые классы. Все не тестовые методы должны находится в других модулях, не в директории tests.