qase-tms / qase-python

Qase TMS Python SDK
https://developers.qase.io
26 stars 26 forks source link

Report crashes if using --video option for pytest-playwright in pytest.ini #279

Open Egzekk opened 1 day ago

Egzekk commented 1 day ago

If we use --video on option or --video retain-on-failure in pytest.ini or pyproject.toml as pytest's addopts argument, the qase is not uploading the video correctly and is giving an error:

Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/threading.py", line 1075, in _bootstrap_inner
    self.run()
  File "/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/threading.py", line 1012, in run
    self._target(*self._args, **self._kwargs)
  File "/home/runner/.cache/pypoetry/virtualenvs/automation-tests-6OnjhVOy-py3.12/lib/python3.12/site-packages/qase/commons/reporters/testops.py", line 79, in _send_results_threaded
    self.client.send_results(self.project_code, self.run_id, results)
  File "/home/runner/.cache/pypoetry/virtualenvs/automation-tests-6OnjhVOy-py3.12/lib/python3.12/site-packages/qase/commons/client/api_v1_client.py", line 127, in send_results
    results_to_send = [self._prepare_result(project_code, result) for result in results]
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/.cache/pypoetry/virtualenvs/automation-tests-6OnjhVOy-py3.12/lib/python3.12/site-packages/qase/commons/client/api_v1_client.py", line 142, in _prepare_result
    attached.extend(self._upload_attachment(project_code, attachment))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/.cache/pypoetry/virtualenvs/automation-tests-6OnjhVOy-py3.12/lib/python3.12/site-packages/qase/commons/client/api_v1_client.py", line 92, in _upload_attachment
    raise ReporterException(e)
qase.commons.exceptions.reporter.ReporterException: [Errno 2] No such file or directory: '/tmp/playwright-pytest-qrqm08jg/7d88b43d4faddafbcecb954bf38990.webm'

Even if we add another option: --output=results/playwright it still throws an error as above.

The above mentioned options are officialy supported by playwright for pytest: https://playwright.dev/python/docs/test-runners

Could you please take a look at that? It is a quite an important feature for us to have.

gibiw commented 19 hours ago

@Egzekk Hi!

Steps to solve the problem:

Configure Playwright to record video for all tests

@pytest.fixture(scope="session") def browser_context_args(browser_context_args): return { **browser_context_args, "record_video_dir": "./videos", # Directory where videos will be saved "record_video_size": {"width": 1280, "height": 720} # Video resolution }


- add `--video on` or `--video retain-on-failure` parameter
Egzekk commented 14 hours ago

The issue has been resolved. For those encountering this problem, I recommend passing "record_video_dir" as browser_context_args["record_video_dir"]. This approach preserves the original naming conventions after the test and creates a default folder structure for each test. If you specify any other path, it will not follow the same naming convention or folder structure, resulting in a file with a random string name.

Egzekk commented 12 hours ago

After further testing, I've encountered an issue with the suggested configuration:

@pytest.fixture(scope="function")
def browser_context_args(browser_context_args):
    return {
        **browser_context_args,
        "record_video_dir": "results/playwright",  # Directory for saving videos
        "record_video_size": {"width": 1280, "height": 720},  # Video resolution
    }

When using the output=results/playwright flag in pytest.ini, an additional video file with a random string name is created next to the original one, but outside any folders, as shown below:

image

Expected behavior:

Screenshot 2024-09-27 at 21 12 53

Without the output=results/playwright flag, it outputs videos with random names and no folder structure, which is also problematic. Managing many tests and videos becomes cumbersome due to this duplication and disorganization. Could you please check it and adjust?