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

Dealing with embedded images better #18

Open
adam6806 opened this issue Dec 3, 2013 · 0 comments
Open

Dealing with embedded images better #18

adam6806 opened this issue Dec 3, 2013 · 0 comments

Comments

@adam6806
Copy link

adam6806 commented Dec 3, 2013

I'm going to start using embedded images because I like the idea of not have screenshots building up everywhere. However when using this code I ran into a problem with the feature template.

encoded_img = @browser.driver.screenshot_as(:base64)
embed("data:image/png;base64,#{encoded_img}",'image/png')

Based on the feature template the resulting HTML is as follows.

src="images/data:image/png;base64,iVBORw0.....

In order to get the embedded image to display I had to remove "images/" from the feature template.

<img id='<%= scenario.image_id %>' style='display: none' src='<%= feature.directory_prefix_for(feature.file) %><%= scenario.image %>'/>

This works for me but it would be nice if instead of appending the images/ to everything in the features template it was appended in the HTML file here with the scenario image file name.

def embed(src, mime_type, label)
    case(mime_type)
    when /^image\/(png|gif|jpg|jpeg)/
      embed_image(src, label)
    end
end

def embed_image(src, label)
    @report.current_scenario.image = src.split(separator).last
    @report.current_scenario.image_label = label
    @report.current_scenario.image_id = "img_#{@img_id}"
    @img_id += 1
    filename = "#{File.dirname(@path)}#{separator}images"
    FileUtils.cp src, filename
end

It looks as though it would be possible to account for embedded images here and either apply the "images/" to the front or not.

Thanks,
Adam

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

1 participant