无法使用RSpec测试获取水豚截图
我查阅了Github文档,通过谷歌搜索找到了答案,但没有找到为什么水豚截图没有保存任何失败截图的答案 这是我目前为我的应用程序所做的设置 Gemfile无法使用RSpec测试获取水豚截图,rspec,capybara,Rspec,Capybara,我查阅了Github文档,通过谷歌搜索找到了答案,但没有找到为什么水豚截图没有保存任何失败截图的答案 这是我目前为我的应用程序所做的设置 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
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)
特殊助手
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
主页\u 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
我尝试了几种不同的方法来实现这一点,但我始终无法获得一个屏幕截图来避免失败。我可以手动调用screenshot函数,但是考虑到gem应该在测试失败时自动生成,我觉得有些不对劲。有趣的是,我可以让宝石的黄瓜部分工作得很好。其他人有没有遇到过让水豚截图与RSpec合作的问题?如果有任何帮助,我们将不胜感激。我建议用一个可重复性最低的示例来打开问题。您是否可以将代码示例减少到重新产生问题的最小示例,以及您可能收到的任何错误消息(或指定您没有收到任何错误消息)?看看这是否会使问题变得更简单。而且,我根本没有收到任何错误消息。这就好像需要注册的任何挂钩都没有正确注册一样。感谢您让我知道如何修复
未知方法render
。)
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