-
Notifications
You must be signed in to change notification settings - Fork 0
/
сonftest.py
51 lines (43 loc) · 1.75 KB
/
сonftest.py
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
from pathlib import Path
from playwright.sync_api import sync_playwright
from slugify import slugify
from pages.app import App
from settings.settings import *
import pytest
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
pytest_html = item.config.pluginmanager.getplugin("html")
outcome = yield
screen_file = ''
report = outcome.get_result()
extra = getattr(report, "extra", [])
if report.when == "call":
if report.failed and "app_without_auth" in item.funcargs:
app_without_auth = item.funcargs["app_without_auth"]
screenshot_dir = Path("screenshots")
screenshot_dir.mkdir(exist_ok=True)
screen_file = str(screenshot_dir / f"{slugify(item.nodeid)}.png")
app_without_auth.page.screenshot(path=screen_file)
if report.failed and "app" in item.funcargs:
app = item.funcargs["app"]
screenshot_dir = Path("screenshots")
screenshot_dir.mkdir(exist_ok=True)
screen_file = str(screenshot_dir / f"{slugify(item.nodeid)}.png")
app.page.screenshot(path=screen_file)
xfail = hasattr(report, "wasxfail")
if (report.skipped and xfail) or (report.failed and not xfail):
# add the screenshots to the html report
extra.append(pytest_html.extras.png(screen_file))
report.extra = extra
@pytest.fixture
def get_playwright():
with sync_playwright() as p:
yield p
@pytest.fixture
def app(get_playwright):
app = App(get_playwright, base_url=base_url_settings)
yield app
@pytest.fixture
def app_without_auth(get_playwright, base_url=base_url_settings):
app = App(get_playwright, base_url=base_url_settings, storage_state=None)
yield app