如何使用minitest-reporter嵌入屏幕截图

时间:2015-04-14 10:02:03

标签: ruby reporting-services jenkins minitest

我正在和Jenkins一起使用minitest来制作测试报告。目前我正在使用Minitest::Reporters::JUnitReporter - https://github.com/kern/minitest-reporters。这似乎给出了非常简洁的结果。

唯一缺少的是嵌入式屏幕截图,特别是失败的测试。

如何制作包含屏幕截图的Jenkins友好测试报告?如果它有帮助,我愿意使用其中一个Minitest::Reporters

由于

1 个答案:

答案 0 :(得分:1)

您可以使用capybara-screenshot gem:https://github.com/mattheworiordan/capybara-screenshot

Gemfile:

group :test do
  gem 'capybara', '2.6.0'   
  gem 'selenium-webdriver', '2.49.0'
  gem 'poltergeist', '1.8.1'
  gem 'capybara-screenshot', '1.0.11'
end

test_helper.rb中:

# default rails test configuration
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'    

# configure webtests with capybara and poltergeist (headless)
require 'capybara/rails'
require 'capybara/poltergeist'
require 'capybara-screenshot/minitest'

if ENV['HEADLESS'] == 'true'
  # headless driver configuration
  Capybara.default_driver = :poltergeist
else
  Capybara.default_driver = :selenium
end

Capybara::Screenshot.prune_strategy = :keep_last_run   # keep screenshots only from the last test run
Capybara.save_and_open_page_path = File.join(Rails.root, "test/screenshots")   # where to save screenshots

# default test class for unit tests
class ActiveSupport::TestCase
  # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
  fixtures :all

  # Add more helper methods to be used by all tests here...
end

# default test class for webtests
class ActionDispatch::IntegrationTest
  include Capybara::DSL
  include Capybara::Screenshot::MiniTestPlugin
end