sj26 / rspec_junit_formatter

RSpec results that your CI can read

Home Page:http://rubygems.org/gems/rspec_junit_formatter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add screenshot in the JUnit output for system tests

matteeyah opened this issue · comments

Summary

RSpec system tests produce a failure screenshot. The path of the screenshot is printed out when the test fails.

Proposal

Parse the test output and grab the path to the screenshot and output it the JUnit XML output.

You can configure it the hacky way if you like. I wanted to have my screenshots made with the rails screenshot helper easily accessable in Gitlab-CI, so I did the following:

module ScreenshotForCiHelper
  def take_screenshot
    super
    @screenshot_image_path = absolute_image_path.delete_prefix(Rails.root.to_s)
  end
end

RSpec.configure do |config|
  config.include ScreenshotForCiHelper, type: :system
  config.around(:each, type: :system) do |example|
    @screenshot_image_path = nil
    example.run
    example.metadata[:stdout] = "[[ATTACHMENT|#{@screenshot_image_path}]]" unless @screenshot_image_path.nil?
  end
end

Now everytime a screenshot is taken, its path is saved in the JUinit XML output like gitlab needs it.
See: https://docs.gitlab.com/ee/ci/testing/unit_test_reports.html#view-junit-screenshots-on-gitlab

This gem is for outputting junit compatible xml. There is nothing in that standard for outputting screenshots like this. I'd suggest moving to a dedicated format that can have attachments, or writing an extension to integration your screenshot tool with rspec output :-)