Skip to content

Commit

Permalink
feature: improve the handling of videos and traces for Playwright tests
Browse files Browse the repository at this point in the history
You don't need to create a `conftest.py` file anymore. The video and trace will be attached to the test result
automatically.
You can configure the video and trace recording using the following parameters:

- `--video on` - add a video to each test
- `--video retain-on-failure` - add a video to each filed test
- `--tracing on` - add a trace to each test
- `--tracing retain-on-failure` - add a trace to each filed test
- `--output` - the directory where the video and trace will be saved. By default, the video and trace will be saved in
  the `test-results` directory.
  • Loading branch information
gibiw committed Sep 30, 2024
1 parent 940834e commit dba83dd
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
16 changes: 16 additions & 0 deletions qase-pytest/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# qase-pytest 6.1.5

## What's new

Improved the handling of videos and traces for Playwright tests.
You don't need to create a `conftest.py` file anymore. The video and trace will be attached to the test result
automatically.
You can configure the video and trace recording using the following parameters:

- `--video on` - add a video to each test
- `--video retain-on-failure` - add a video to each filed test
- `--tracing on` - add a trace to each test
- `--tracing retain-on-failure` - add a trace to each filed test
- `--output` - the directory where the video and trace will be saved. By default, the video and trace will be saved in
the `test-results` directory.

# qase-pytest 6.1.4

## What's new
Expand Down
4 changes: 2 additions & 2 deletions qase-pytest/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "qase-pytest"
version = "6.1.4"
version = "6.1.5"
description = "Qase Pytest Plugin for Qase TestOps and Qase Report"
readme = "README.md"
keywords = ["qase", "pytest", "plugin", "testops", "report", "qase reporting", "test observability"]
Expand All @@ -29,7 +29,7 @@ classifiers = [
]
requires-python = ">=3.7"
dependencies = [
"qase-python-commons~=3.1.8",
"qase-python-commons~=3.1.9",
"pytest>=7.4.4",
"filelock~=3.12.2",
"more_itertools",
Expand Down
9 changes: 9 additions & 0 deletions qase-pytest/src/qase/pytest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ def _add_markers(config):
def setup_config_manager(config):
config_manager = ConfigManager()
for option in config.option.__dict__:
if option == "output" and config.option.__dict__[option] is not None:
config_manager.config.framework.playwright.set_output_dir(config.option.__dict__[option])

if option == "video" and config.option.__dict__[option] is not None:
config_manager.config.framework.playwright.set_video(config.option.__dict__[option])

if option == "tracing" and config.option.__dict__[option] is not None:
config_manager.config.framework.playwright.set_trace(config.option.__dict__[option])

if option.startswith("qase_"):
if option == "qase_mode" and config.option.__dict__[option] is not None:
config_manager.config.set_mode(config.option.__dict__[option])
Expand Down
31 changes: 27 additions & 4 deletions qase-pytest/src/qase/pytest/plugin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
import pathlib
from typing import Tuple, Union
import mimetypes

from qase.commons.models.config.framework import Trace
from qase.commons.models.result import Result, Field
from qase.commons.models.attachment import Attachment
from qase.commons.models.suite import Suite
Expand Down Expand Up @@ -46,6 +48,7 @@ def __init__(
):
self.runtime = Runtime()
self.reporter = reporter
self.config = reporter.config
self.run_id = None
self.execution_plan = reporter.get_execution_plan()
self._current_item = None
Expand Down Expand Up @@ -175,12 +178,22 @@ def _attach_logs():
_attach_logs()

if report.when == "call":
# Attach the video to the test result
# Attach the video and the trace to the test result
if hasattr(item, 'funcargs') and 'page' in item.funcargs:
video = item.funcargs['page'].video
if not video:
page = item.funcargs['page']
if not page.video:
return
self.add_attachments(video.path())

folder_name = self.__build_folder_name(item)
output_dir = self.config.framework.playwright.output_dir
base_path = os.path.join(os.getcwd(), output_dir, folder_name)

video_path = os.path.join(base_path, "video.webm")
self.add_attachments(video_path)

if self.config.framework.playwright.trace != Trace.off:
trace_path = os.path.join(base_path, "trace.zip")
self.add_attachments(trace_path)
else:
yield

Expand Down Expand Up @@ -343,6 +356,16 @@ def _get_suite(self, item):

self.runtime.result.suite = Suite(title, package)

@staticmethod
def __build_folder_name(item):
return (
item.location[0].replace(os.sep, "-").replace(".", "-").replace("_", "-")
+ "-"
+ item.originalname.replace(".", "-").replace("_", "-")
+ "-"
+ item.funcargs['browser_name']
)


class QasePytestPluginSingleton:
_instance = None
Expand Down

0 comments on commit dba83dd

Please sign in to comment.