Skip to content
Merged
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
16 changes: 14 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def pytest_runtest_makereport(item, call):


@pytest.fixture(autouse=True)
def capture_failure_artifacts(request, page, context, config):
def capture_failure_artifacts(request, config):
"""
Capture screenshot and Playwright trace when a test fails
and attach them to the Allure report.
Expand All @@ -149,8 +149,19 @@ def capture_failure_artifacts(request, page, context, config):

# Get the test execution report
report = getattr(request.node, "rep_call", None)

# Only continue if the test actually failed
if not report or not report.failed:
return

# Try to retrieve page and context from the test request.
# This prevents unit tests from unnecessarliy creating Playwright objects.
page = request.node.funcargs.get("page")
context = request.node.funcargs.get("context")

# If the test doesn't use Playwright, there is nothing to capture.
if page is None or context is None:
return

# Create report directories
screenshot_directory = Path("reports/screenshots")
Expand Down Expand Up @@ -180,7 +191,8 @@ def capture_failure_artifacts(request, page, context, config):
# --------------------------------
if config.get("reports.trace"):
trace_path = (trace_directory/f"{test_name}.zip")
context.tracing.stop(path=str(trace_path))
if config.get("reports.trace"):
context.tracing.stop(path=str(trace_path))
print(f"Trace saved: {trace_path}")

# Attach trace to Allure
Expand Down
Loading