Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reports missing <img> tags for screenshots #237

Closed
anothermattbrown opened this issue May 12, 2020 · 7 comments
Closed

reports missing <img> tags for screenshots #237

anothermattbrown opened this issue May 12, 2020 · 7 comments

Comments

@anothermattbrown
Copy link

The generated report html is missing the <img> tag for screenshots.

Example test:

def test_foo(selenium):
    selenium.get('http://google.com')
    assert False

command:

$ pytest --driver chrome --driver-path path/to/chromedriver test.py --html report.html

The report shows a blank square instead of an image:
Screen Shot 2020-05-12 at 12 46 50 PM

In the inspector, there's an empty <a> tag:
Screen Shot 2020-05-12 at 12 47 18 PM

The link in the <a> tag goes to the (expected) screenshot on disk.

I can't tell if this is a problem with pytest-selenium, pytest-html, or something else. Any help would be appreciated.

@dhalperi
Copy link

dhalperi commented May 12, 2020

I can shed some light.

  1. Here's the code in pytest-selenium that gathers the screenshot and passes it to pytest-html:

    def _gather_screenshot(item, report, driver, summary, extra):
    try:
    screenshot = driver.get_screenshot_as_base64()
    except Exception as e:
    summary.append("WARNING: Failed to gather screenshot: {0}".format(e))
    return
    pytest_html = item.config.pluginmanager.getplugin("html")
    if pytest_html is not None:
    # add screenshot to the html report
    extra.append(pytest_html.extras.image(screenshot, "Screenshot"))

  2. Here's the code in pytest-html that handles that call and generates the report: https://github.com/pytest-dev/pytest-html/blob/103c849cac7b8e0dbaf0a151a541a8c085fb008e/pytest_html/plugin.py#L293-L323

The flow is as follows:

The fix could be in either place: pytest-selenium could create the asset before passing it in, or pytest-html could use the img tag even when it creates the asset. I haven't yet been able to determine which fix is the right one.

@dhalperi
Copy link

Okay, digging, it looks like this was an unintentional result of refactoring in pytest-html: pytest-dev/pytest-html@588c41b

Before that commit, the img tag was applied for created assets. That no longer happens in the refactored code.

@dhalperi
Copy link

Cross-linking to existing pytest-html issue: pytest-dev/pytest-html#265

@anothermattbrown
Copy link
Author

Thanks @dhalperi. For now, I confirmed that --self-contained-html is a work-around.

@BeyondEvil
Copy link
Contributor

Hopefully in not a too distant future we'll release a new version of pytest-html, which will solve this issue.

@andreashetz
Copy link

Please fix it. Thanks

@anothermattbrown
Copy link
Author

Fixed by pytest-dev/pytest-html#298

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants