我查看了Github的文档,通过谷歌搜索寻找答案,并且无法找到答案为什么capybara-screenshot不能保存任何故障截图。< / p>
这是我目前为我的申请设置的设置。
的Gemfile
group :development, :test do
gem 'meta_request'
gem 'factory_girl_rails'
gem 'faker'
gem 'rspec-rails', '~> 2.14.1'
gem 'capybara'
gem 'capybara-webkit'
gem 'capybara-screenshot'
gem 'cucumber-rails', :require => false
gem 'database_cleaner'
gem 'selenium-webdriver'
gem 'pry'
end
Gemfile.lock的
capybara (2.3.0)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
capybara-screenshot (0.3.19)
capybara (>= 1.0, < 3)
launchy
capybara-webkit (1.1.0)
capybara (~> 2.0, >= 2.0.2)
json
rspec-core (2.14.8)
rspec-expectations (2.14.5)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.6)
rspec-rails (2.14.2)
actionpack (>= 3.0)
activemodel (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
初始化/ capybara.rb
Capybara.register_driver :selenium_chrome do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
Capybara::Screenshot.register_driver(:selenium_chrome) do |driver, path|
driver.browser.save_screenshot(path)
end
spec_helper
require 'rspec/autorun'
# Include Capybara Capabilities
require 'capybara/rspec'
require 'capybara/rails'
require 'capybara-screenshot/rspec'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
Capybara.save_and_open_page_path = "#{Rails.root.join("tmp")}/acceptance_tests/"
Capybara::Screenshot.append_timestamp = false
Capybara::Screenshot.register_filename_prefix_formatter(:rspec) do |example|
"screenshot_#{example.description.gsub(' ', '-').gsub(/^.*\/spec\//,'')}"
end
Capybara::Screenshot.autosave_on_failure = true
home_page_spec.rb
require 'spec_helper'
shared_examples 'home_page_tests' do |driver|
context "When using the #{driver.to_s} driver" do
before do
Capybara.current_driver = driver
end
describe 'home page', :js => true do
context 'the user is not logged into the application' do
it 'displays login and sign in buttons' do
visit root_path
expect(page).to have_selector('.btn', text:'Sign i')
end
end
end
end
end
describe 'Running the homepage tests' do
it_behaves_like 'home_page_tests', :selenium_chrome
end
我已经尝试了多种变体来实现这一功能,但我无法获得屏幕截图以便在失败时保存。我可以手动调用截图函数,但鉴于测试失败时宝石应该自动生成,我觉得有些不对劲。有趣的是,我能够让Gem的黄瓜部分工作得很好。有没有其他人在使用RSP进行capybara-screenshot时遇到任何麻烦?任何帮助将不胜感激。