-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
62 lines (53 loc) · 2.05 KB
/
conftest.py
File metadata and controls
62 lines (53 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import pytest
import allure
from playwright.sync_api import Playwright
# 1. Фикстура для создания Environment в Allure (Сессионная)
@pytest.fixture(scope="session", autouse=True)
def create_allure_environment():
"""
Автоматически создает файл environment.properties в папке allure-results.
"""
yield # Ждем завершения всех тестов
allure_results_path = "allure-results"
if not os.path.exists(allure_results_path):
os.makedirs(allure_results_path)
env_file_path = os.path.join(allure_results_path, "environment.properties")
with open(env_file_path, "w") as f:
f.write("Project=MyProject\n")
f.write("Browser=Chromium\n")
f.write("URL=https://mwtestconsultancy.co.uk\n")
# 2. Фикстура для API
@pytest.fixture
def api(playwright: Playwright):
request_context = playwright.request.new_context(
base_url="https://mwtestconsultancy.co.uk"
)
yield request_context
request_context.dispose()
# 3. Фикстура для Home Page
@pytest.fixture
def home_page(page):
from pages.home_page import HomePage
return HomePage(page)
# 4. Хук для скриншотов при падении
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
rep = outcome.get_result()
if rep.when == "call" and rep.failed:
page = None
if "home_page" in item.funcargs:
page = item.funcargs["home_page"].page
elif "page" in item.funcargs:
page = item.funcargs["page"]
if page:
try:
screenshot = page.screenshot(full_page=True)
allure.attach(
screenshot,
name=f"Failure_Screenshot_{item.name}",
attachment_type=allure.attachment_type.PNG
)
except Exception as e:
print(f"Не удалось сделать скриншот: {e}")