-
Notifications
You must be signed in to change notification settings - Fork 83
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)
