I've looked through the Github documentations, looked for answers through google searches, and haven't been able to find an answer to why capybara-screenshot isn't saving any screenshots on failures.
Here's the setup I currently have for my application.
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)
initializers/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
I've tried several variations to get this working, but I never am able to get a screenshot to save on failure. I can manually call the screenshot function, but given that the gem is supposed to autogenerate when a test fails, I feel something is wrong. Interesting though, I am able to get the cucumber portion of the Gem working just fine. Has anyone else had any troubles with getting capybara-screenshot working with RSpec? Any help would be appreciated.
unknown method render..) - Nakilon