pytest-dev / pytest-dev/pytest-html
Attaching video URL after every test run in pytest html report
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 779
- Forks
- 260
- PR merge metrics
- No merged PRs in 30d
Description
After every test run i am getting the video URL but when the report gets generated the URL is only shown for the 2nd test case which is of the 1st one and for 1st one it doesn't show anything.
Note: the video URLs are generated correctly for each test cases it just that i am not able to properly attach the link to each test case in the report.
can someone help me with this please:
Below is my code snippet:
@pytest.fixture(scope="function")
def test_obj(browser, browser_version, platform, os_version, request):
global driver
driver_fact = DriverFactory()
test_name = os.environ.get('PYTEST_CURRENT_TEST').split(':')[-1].split(' ')[0]
driver = driver_fact.get_web_driver(browser, browser_version, platform, os_version, test_name)
print(driver)
browserstack_obj = BrowserStack_Library()
active_session_id = browserstack_obj.get_active_session_id()
driver.maximize_window()
request.cls.driver = driver
yield
driver.quit()
global video_url
video_url = browserstack_obj.get_session_url(active_session_id)
@pytest.mark.hookwrapper
def pytest_runtest_makereport(multicall, item):
pytest_html = item.config.pluginmanager.getplugin('html')
outcome = yield
report = outcome.get_result()
extra = getattr(report, 'extra', [])
if report.when == "call":
extra.append(pytest_html.extras.url(video_url))
xfail = hasattr(report, 'wasxfail')
if (report.skipped and xfail) or (report.failed and not xfail):
file_name = report.nodeid.replace("::", "_") + ".png"
# _capture_screenshot(file_name)
if file_name:
html = '<div><img src="%s" alt="screenshot" style="width:304px;height:228px;" ' \
'onclick="window.open(this.src)" align="right"/></div>' % file_name
extra.append(pytest_html.extras.html(html))
report.extra = extra

Contributor guide
No contributing guide indexed for this repository
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 at the function-scoped test_obj fixture and the pytest_runtest_makereport hook, tracing when video_url is assigned and when report.extra is populated. Reproduce the report with multiple tests and verify that each test row contains its own video URL.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100