Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Virtual Environment
venv/
env/
ENV/

# IDE
.idea/
.vscode/
*.iml

# Python
__pycache__/
*.pyc
*.pyo
*.pyd
.Python

# Testing
.pytest_cache/
.coverage
htmlcov/

# OS
.DS_Store
Thumbs.db
Binary file modified README.md
Binary file not shown.
1 change: 1 addition & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# tests package
14 changes: 14 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pytest
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from urls import Urls


@pytest.fixture(scope="function")
def driver():
chrome_options = Options()
chrome_options.add_argument("--window-size=1920,1080")
driver = webdriver.Chrome(options=chrome_options)
driver.get(Urls.HOME_PAGE)
yield driver
driver.quit()
7 changes: 7 additions & 0 deletions generate_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import time
import random

def generate_email():
timestamp = int(time.time() * 1000)
random_num = random.randint(1, 9999)
return f"testuser_{timestamp}_{random_num}@example.com"
41 changes: 41 additions & 0 deletions locators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from selenium.webdriver.common.by import By


class LoginLocators:
LOGIN_BUTTON = (By.XPATH, "//button[contains(text(), 'Вход и регистрация')]")
EMAIL_INPUT = (By.CSS_SELECTOR, "input[placeholder='Введите Email']")
PASSWORD_INPUT = (By.CSS_SELECTOR, "input[placeholder='Пароль']")
SUBMIT_BUTTON = (By.XPATH, "//button[contains(text(), 'Войти')]")
USER_AVATAR = (By.CLASS_NAME, "circleSmall")
USER_NAME = (By.CLASS_NAME, "profileText")
POST_AD_BUTTON = (By.XPATH, "//button[contains(text(), 'Разместить объявление')]")


class RegistrationLocators:
NO_ACCOUNT_BUTTON = (By.XPATH, "//button[contains(text(), 'Нет аккаунта')]")
EMAIL_INPUT = (By.CSS_SELECTOR, "input[placeholder='Введите Email']")
PASSWORD_INPUT = (By.CSS_SELECTOR, "input[placeholder='Пароль']")
CONFIRM_PASSWORD_INPUT = (By.CSS_SELECTOR, "input[placeholder='Повторите пароль']")
CREATE_ACCOUNT_BUTTON = (By.XPATH, "//button[contains(text(), 'Создать аккаунт')]")



class LogoutLocators:
LOGOUT_BUTTON = (By.XPATH, "//button[contains(text(), 'Выйти')]")
LOGIN_BUTTON = (By.XPATH, "//button[contains(text(), 'Вход и регистрация')]")


class AdCreationLocators:
MODAL_TITLE = (By.XPATH, "//h1[contains(text(), 'Чтобы разместить объявление, авторизуйтесь')]")
POST_AD_BUTTON = (By.XPATH, "//button[contains(text(), 'Разместить объявление')]")
TITLE_INPUT = (By.CSS_SELECTOR, "input[placeholder='Название']")
DESCRIPTION_TEXTAREA = (By.CSS_SELECTOR, "textarea[placeholder='Описание товара']")
PRICE_INPUT = (By.CSS_SELECTOR, "input[placeholder='Стоимость']")
DROPDOWN_CATEGORIES = (By.XPATH, '//input[@name="category"]/following-sibling::button[contains(@class, "dropDownMenu_arrowDown__pfGL1")]')
SELECT_CATEGORIES = (By.XPATH, "//span[text()='Авто']")
CITY_DROPDOWN = (By.XPATH, '//input[@name="city"]/following-sibling::button[contains(@class, "dropDownMenu_arrowDown__pfGL1")]')
SELECT_CITY = (By.XPATH, "//span[text()='Казань']")
RADIO_BUTTON = By.XPATH, '//input[@type="radio" and @value="Б/У"]'
PUBLISH_BUTTON = (By.XPATH, "//button[contains(text(), 'Опубликовать')]")
MY_ADS_BLOCK = (By.XPATH, "//h1[contains(text(), 'Мои объявления')]")
AD_TITLE = (By.XPATH, "//div[@class='card']//h2")
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
### `requirements.txt`
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# tests package
62 changes: 62 additions & 0 deletions tests/test_creating_an_ad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from ..locators import LoginLocators, AdCreationLocators
from ..user_data import UserData

class TestAdCreation:

def test_create_ad_unauthorized(self, driver):

driver.find_element(*LoginLocators.POST_AD_BUTTON).click()

wait = WebDriverWait(driver, 5)

assert wait.until(EC.visibility_of_element_located(AdCreationLocators.MODAL_TITLE))

def test_create_ad_authorized(self, driver):
email = UserData.USER["email"]
password = UserData.USER["password"]
wait = WebDriverWait(driver, 10)

driver.find_element(*LoginLocators.LOGIN_BUTTON).click()
wait.until(
EC.presence_of_element_located(LoginLocators.EMAIL_INPUT)
)
driver.find_element(*LoginLocators.EMAIL_INPUT).send_keys(email)
driver.find_element(*LoginLocators.PASSWORD_INPUT).send_keys(password)
driver.find_element(*LoginLocators.SUBMIT_BUTTON).click()

wait.until(
EC.visibility_of_element_located(LoginLocators.USER_AVATAR))
driver.find_element(*AdCreationLocators.POST_AD_BUTTON).click()

driver.find_element(*AdCreationLocators.TITLE_INPUT).send_keys(UserData.AD_DATA["title"])
driver.find_element(*AdCreationLocators.DESCRIPTION_TEXTAREA).send_keys(UserData.AD_DATA["description"])
driver.find_element(*AdCreationLocators.PRICE_INPUT).send_keys(UserData.AD_DATA["price"])

driver.find_element(*AdCreationLocators.DROPDOWN_CATEGORIES).click()
driver.find_element(*AdCreationLocators.SELECT_CATEGORIES).click()

driver.find_element(*AdCreationLocators.CITY_DROPDOWN).click()
driver.find_element(*AdCreationLocators.SELECT_CITY).click()

radio_button = wait.until(EC.presence_of_element_located(AdCreationLocators.RADIO_BUTTON))
driver.execute_script("arguments[0].scrollIntoView(true);", radio_button)
driver.execute_script("arguments[0].click();", radio_button)

driver.find_element(*AdCreationLocators.PUBLISH_BUTTON).click()

wait.until(
EC.visibility_of_element_located(LoginLocators.USER_AVATAR))

driver.find_element(*LoginLocators.USER_AVATAR).click()


wait.until(
EC.presence_of_element_located(AdCreationLocators.MY_ADS_BLOCK))

ad_title_element = driver.find_element(*AdCreationLocators.AD_TITLE)

tit = UserData.AD_DATA["title"]
assert tit in ad_title_element.text
29 changes: 29 additions & 0 deletions tests/test_user_login.py

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from ..locators import LoginLocators

class TestLogin:
def test_successful_login(self, driver, valid_user):
email = valid_user["email"]
password = valid_user["password"]

driver.find_element(*LoginLocators.LOGIN_BUTTON).click()
WebDriverWait(driver, 10).until(
EC.presence_of_element_located(LoginLocators.EMAIL_INPUT)
)
driver.find_element(*LoginLocators.EMAIL_INPUT).send_keys(email)
driver.find_element(*LoginLocators.PASSWORD_INPUT).send_keys(password)
driver.find_element(*LoginLocators.SUBMIT_BUTTON).click()

wait = WebDriverWait(driver, 10)

assert wait.until(EC.visibility_of_element_located(LoginLocators.POST_AD_BUTTON)), \
"Кнопка 'Разместить объявление' не отображается после входа"

avatar = wait.until(EC.visibility_of_element_located(LoginLocators.USER_AVATAR))
assert avatar.is_displayed(), "Аватар пользователя не отображается"

user_name_element = wait.until(EC.visibility_of_element_located(LoginLocators.USER_NAME))
assert user_name_element.is_displayed(), "Имя пользователя не отображается"
assert valid_user["expected_username_part"] in user_name_element.text, \
f"Имя пользователя не содержит '{valid_user['expected_username_part']}', фактическое: '{user_name_element.text}'"
37 changes: 37 additions & 0 deletions tests/test_user_logout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from ..locators import LoginLocators, LogoutLocators
from ..user_data import UserData

class TestLogout:

def test_successful_logout(self, driver):
email = UserData.USER["email"]
password = UserData.USER["password"]

driver.find_element(*LoginLocators.LOGIN_BUTTON).click()
WebDriverWait(driver, 10).until(
EC.presence_of_element_located(LoginLocators.EMAIL_INPUT)
)
driver.find_element(*LoginLocators.EMAIL_INPUT).send_keys(email)
driver.find_element(*LoginLocators.PASSWORD_INPUT).send_keys(password)
driver.find_element(*LoginLocators.SUBMIT_BUTTON).click()

WebDriverWait(driver, 10).until(
EC.presence_of_element_located(LogoutLocators.LOGOUT_BUTTON)
)

driver.find_element(*LogoutLocators.LOGOUT_BUTTON).click()

WebDriverWait(driver, 10).until(
EC.presence_of_element_located(LogoutLocators.LOGIN_BUTTON)
)

avatars = driver.find_elements(*LoginLocators.USER_AVATAR)
user_names = driver.find_elements(*LoginLocators.USER_NAME)
login_button = driver.find_element(*LogoutLocators.LOGIN_BUTTON)

assert len(avatars) == 0
assert len(user_names) == 0
assert login_button.is_displayed()
assert "Вход и регистрация" in login_button.text
36 changes: 36 additions & 0 deletions tests/test_user_registration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from ..locators import LoginLocators, RegistrationLocators
from ..generate_email import generate_email

class TestRegistration:

def test_successful_registration(self, driver):
email = generate_email()
password = "test12345"

driver.find_element(*LoginLocators.LOGIN_BUTTON).click()
WebDriverWait(driver, 10).until(
EC.element_to_be_clickable(RegistrationLocators.NO_ACCOUNT_BUTTON)
)
driver.find_element(*RegistrationLocators.NO_ACCOUNT_BUTTON).click()

driver.find_element(*RegistrationLocators.EMAIL_INPUT).send_keys(email)
driver.find_element(*RegistrationLocators.PASSWORD_INPUT).send_keys(password)
driver.find_element(*RegistrationLocators.CONFIRM_PASSWORD_INPUT).send_keys(password)
driver.find_element(*RegistrationLocators.CREATE_ACCOUNT_BUTTON).click()

WebDriverWait(driver, 10).until(
EC.presence_of_element_located(LoginLocators.POST_AD_BUTTON)
)
WebDriverWait(driver, 10).until(
EC.presence_of_element_located(LoginLocators.USER_AVATAR)
)

avatar = driver.find_element(*LoginLocators.USER_AVATAR)
user_name = driver.find_element(*LoginLocators.USER_NAME)

assert avatar.is_displayed()
assert user_name.is_displayed()
assert "User" in user_name.text
4 changes: 4 additions & 0 deletions urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Urls:
URL = "https://qa-desk.education-services.ru"

HOME_PAGE = URL + "/"
16 changes: 16 additions & 0 deletions user_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class UserData:

USER = {
"email": "eva1x@yandex.ru" ,
"password": "test12345" ,
}

AD_DATA = {
"title": "Лучшее" ,
"description": "Почти как новая" ,
"price": "1 500 000" ,
"category": "Авто" ,
"city": "Казань" ,
"condition": "new"

}