capybara-screenshot
capybara-screenshot copied to clipboard
#save_path with relative path output incorrect path to image and html in rspec
Capybara.save_path = 'log'
As result the gem pushes to STDOUT incorrect path to files, like:
file://log/screenshot_xxx.png and we expect there absolute path, like
file:///home/user/yyy/log/screenshot_xxx.png
Same problem for HTML
In additional, it will be nice to have new option, to specify prefix for it. It is extremely useful for continuous integration systems, for instance TravisCI, where assets are uploaded to S3
For now I implemented monkey patch for my needs:
require 'capybara-screenshot/rspec/text_reporter'
module Capybara
module Screenshot
module RSpec
module TextReporter
private
def output_screenshot_info(example)
return unless (meta = example.metadata[:screenshot])
output.puts(build_text("HTML screenshot: #{build_path(meta[:html])}")) if meta[:html]
output.puts(build_text("Image screenshot: #{build_path(meta[:image])}")) if meta[:image]
end
def build_text(value)
long_padding + CapybaraScreenshot::Helpers.yellow(value)
end
def build_path(relative_path)
if ENV['CI'] == 'true'
File.join(ENV['CI_ARTIFACTS_PATH'], relative_path)
else
'file://' + File.expand_path(File.join(__dir__, '..', '..', relative_path))
end
end
end
end
end
Mind I ask why don't simply use an absolute path?
@mattheworiordan you are right, it could be a workaround. I care about compatibility and clean interface. For rails, and other cases it is possible to put relative path, and for custom project, like mine we have to use absolute path only. Not good.