microsoft / microsoft/playwright-pytest
[FEATURE] Allow attaching screenshot and video into Allure report
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 563
- Forks
- 90
- Avg merge
- 11m
- Merged PRs (30d)
- 1
Description
I usually use Allure report with PyTest+Playwright.
Test code (intented to fail)
from playwright.sync_api import Page
def test_github_search(page: Page):
page.goto('https://github.com/')
page.focus('input[name="q"]')
page.keyboard.type('playwright')
with page.expect_navigation():
page.keyboard.press('Enter')
first_item = page.query_selector_all('.repo-list-item')[0]
assert 'Playwright' in first_item.text_content()
Motivation
I want to store the video for failed tests.
I don't want to keep sitting at the laptop for observing flaky test failure :)
So I used to attach video into Allure report.
https://zenn.dev/yusukeiwaki/articles/cfda648dc170e5#%E3%83%86%E3%82%B9%E3%83%88%E5%A4%B1%E6%95%97%E6%99%82%E3%81%AE%E3%83%AC%E3%83%9D%E3%83%BC%E3%83%88%E3%81%AB%E5%8B%95%E7%94%BB%E3%82%92%E6%B7%BB%E4%BB%98%E3%81%99%E3%82%8B (Sorry in Japanese)

When we handle a lot of test cases, it is useful to put screenshot and video into Allure report (not in test-report directory), because it is really hard to find the video file from a list of many files for each failure.
Problem
#70 brought very useful feature. Thank you :)
However it doesn't put video and screenshots into Allure report as attachments.
For putting them into Allure report, we still have to write the script like below.
from playwright.sync_api import Page
import pytest
import allure
from slugify import slugify
def pytest_runtest_makereport(item, call) -> None:
if call.when == "call":
if call.excinfo is not None and "page" in item.funcargs:
page: Page = item.funcargs["page"]
# ref: https://stackoverflow.com/q/29929244
allure.attach(
page.screenshot(type='png'),
name=f"{slugify(item.nodeid)}.png",
attachment_type=allure.attachment_type.PNG
)
video_path = page.video.path()
page.context.close() # ensure video saved
allure.attach(
open(video_path, 'rb').read(),
name=f"{slugify(item.nodeid)}.webm",
attachment_type=allure.attachment_type.WEBM
)
@pytest.fixture()
def browser_context_args(browser_context_args, tmpdir_factory: pytest.TempdirFactory):
return {
**browser_context_args,
"record_video_dir": tmpdir_factory.mktemp('videos')
}
Feature Request
Attach screenshot and videos into Allure report when --alluredir is specified (of cource only when --video=on/retain-on-failure or --screenshot=on/retain-on-failure is specified)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the pytest_runtest_makereport hook and the handling of --alluredir, --video, and --screenshot. Check how Playwright saves screenshots and videos, then verify that enabled or failure-retained artifacts appear as Allure attachments without requiring user-written hooks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100