Skip to content

Embed screenshots in HTML formatter fails if src path is relative to the location of formatter #775

@aikhelis

Description

@aikhelis

The "unless" condition here could be improved in distingushing whether src is a path to image or is an encoded data object

def embed(src, mime_type, label)
        case(mime_type)
        when /^image\/(png|gif|jpg|jpeg)/
          unless File.file?(src) or src =~ /^data:image\/(png|gif|jpg|jpeg);base64,/
            type = mime_type =~ /;base[0-9]+$/ ? mime_type : mime_type + ";base64"
            src = "data:" + type + "," + src
          end
          embed_image(src, label)

Problem:
In my case, src is a relative path to the screenshot file, so File.file?(src) ran in the context of the file where html formatter is defined - will return false. This leads to the following src of image in the html report. Thus, image is not found in the report.

src="data:image/png;base64,screenshots/my_screenshot.png"

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 bugDefect / Bug⌛ staleWill soon be closed by stalebot unless there is activity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions