reports missing <img> tags for screenshots
anothermattbrown opened this issue · comments
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:
In the inspector, there's an empty <a>
tag:
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.
I can shed some light.
-
Here's the code in
pytest-selenium
that gathers the screenshot and passes it topytest-html
:pytest-selenium/pytest_selenium/pytest_selenium.py
Lines 291 to 300 in d1d4ff6
-
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:
-
pytest-selenium collects only base64 image bytes, and passes that directly to
pytest-html.extras.image
. -
The code in
pytest-html.extras.image
->extras._make_media_html_div
, however, only uses theimg
code when it's passed a file or URL forcontent
or when the entire report is self-contained.The code in
extras._make_media_html_div
that is actually used is the final case, where code there makes an asset dynamically. In that case, thebase_extra_string
that contains the IMG tag is not used in generating the final HTML.
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.
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.
Cross-linking to existing pytest-html
issue: pytest-dev/pytest-html#265
Thanks @dhalperi. For now, I confirmed that --self-contained-html
is a work-around.
Hopefully in not a too distant future we'll release a new version of pytest-html, which will solve this issue.
Please fix it. Thanks
Fixed by pytest-dev/pytest-html#298