Initial commit
This commit is contained in:
commit
9795660e1f
43 changed files with 2757 additions and 0 deletions
130
tests/ui/conftest.py
Normal file
130
tests/ui/conftest.py
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
import logging
|
||||
import allure
|
||||
import pytest
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.chrome.options import Options
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from datetime import datetime
|
||||
|
||||
from config.ui_config import UIConfig
|
||||
from tests.api.utils.api_client import APIClient
|
||||
from utils import waiters
|
||||
|
||||
from api.utils.api_client import APIClient
|
||||
from api.conftest import *
|
||||
from fixtures.data_fixtures import *
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@pytest.fixture
|
||||
def driver(request):
|
||||
"""Фикстура для браузера"""
|
||||
logger.info("=" * 50)
|
||||
logger.info("Initializing webdriver")
|
||||
|
||||
headless = UIConfig.BROWSER_HEADLESS
|
||||
browser_name = UIConfig.BROWSER_NAME
|
||||
fullscreen = UIConfig.BROWSER_FULLSCREEN
|
||||
|
||||
logger.info(f"Headless: {headless}")
|
||||
logger.info("Browser: {browser_name}")
|
||||
|
||||
logger.info("=" * 50)
|
||||
|
||||
if browser_name == "chrome":
|
||||
options = Options()
|
||||
if headless:
|
||||
options.add_argument("--headless")
|
||||
if fullscreen:
|
||||
options.add_argument("--start-maximized")
|
||||
options.add_argument("--no-sandbox")
|
||||
options.add_argument("--disable-dev-shm-usage")
|
||||
options.add_argument("--window-size=1920,1080")
|
||||
|
||||
driver = webdriver.Chrome(
|
||||
options=options
|
||||
)
|
||||
else:
|
||||
options = webdriver.FirefoxOptions()
|
||||
if headless:
|
||||
options.add_argument("--headless")
|
||||
if fullscreen:
|
||||
options.add_argument("--kiosk")
|
||||
options.add_argument("--width=1920")
|
||||
options.add_argument("--height=1080")
|
||||
driver = webdriver.Firefox(
|
||||
options=options
|
||||
)
|
||||
|
||||
driver.implicitly_wait(10)
|
||||
driver.maximize_window()
|
||||
|
||||
waiters.waiter = WebDriverWait(driver, 10)
|
||||
|
||||
def fin():
|
||||
if request.node.rep_call.failed:
|
||||
try:
|
||||
# Делаем скриншот при падении теста
|
||||
screenshot = driver.get_screenshot_as_png()
|
||||
allure.attach(
|
||||
screenshot,
|
||||
name=f"screenshot_{datetime.now().strftime('%Y%m%d_%H%M%S')}",
|
||||
attachment_type=allure.attachment_type.PNG
|
||||
)
|
||||
|
||||
# Получаем текущий URL
|
||||
current_url = driver.current_url
|
||||
allure.attach(
|
||||
current_url,
|
||||
name="current_url",
|
||||
attachment_type=allure.attachment_type.TEXT
|
||||
)
|
||||
|
||||
# Получаем исходный код страницы
|
||||
page_source = driver.page_source
|
||||
allure.attach(
|
||||
page_source,
|
||||
name="page_source",
|
||||
attachment_type=allure.attachment_type.HTML
|
||||
)
|
||||
except:
|
||||
pass
|
||||
driver.quit()
|
||||
|
||||
request.addfinalizer(fin)
|
||||
|
||||
yield driver
|
||||
driver.quit()
|
||||
|
||||
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
|
||||
def pytest_runtest_makereport(item, call):
|
||||
"""
|
||||
Хук для получения результатов теста
|
||||
"""
|
||||
outcome = yield
|
||||
rep = outcome.get_result()
|
||||
setattr(item, "rep_" + rep.when, rep)
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def gen_data_fixture(auth_admin: APIClient, api_user_data, api_post_data):
|
||||
with allure.step("Generating data"):
|
||||
id = ''
|
||||
user = api_user_data[0]
|
||||
resp = auth_admin.create_user(user)
|
||||
assert resp.status_code == 201
|
||||
id = resp.json()['id']
|
||||
|
||||
post = api_post_data[0]
|
||||
post['userId'] = id
|
||||
auth_admin.create_post(post)
|
||||
yield
|
||||
|
||||
with allure.step("Deleting generated data"):
|
||||
posts = auth_admin.get_all_posts().json()
|
||||
users = auth_admin.get_all_users().json()
|
||||
|
||||
for post in posts:
|
||||
auth_admin.delete_post(post['id'])
|
||||
|
||||
for user in users:
|
||||
auth_admin.delete_user(user['id'])
|
||||
Loading…
Add table
Add a link
Reference in a new issue