capybara-screenshot
capybara-screenshot copied to clipboard
Screenshots not being auto generated with Ruby-Rspec (no rails)
I am using Ruby Rspec to test a webapp that doesn't use rails, thus I don't have a rails_helper.rb
, just a spec_helper.rb
. I can manually trigger a screenshot but I can't figure out how to trigger the screenshots on a failure.
spec_helper.rb:
# frozen-string-literal: true
require 'rspec'
require 'capybara/rspec'
require 'capybara-screenshot/rspec'
require 'capybara/dsl'
require 'selenium-webdriver'
require 'site_prism'
Dir[File.dirname(__FILE__) + '/page_objects/*/*.rb'].each do |page_object|
require page_object
end
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome)
end
Capybara.save_path = "#{Dir.pwd}/screenshots"
Capybara.default_driver = :selenium
Capybara.app_host = "REDACTED"
Capybara.default_max_wait_time = 20
my_spec.rb
describe 'spec' do
before(:each) do
@my_page = login_and_open_my_page
end
it "fails" do
expect(5).to eq(6)
end
end
I have this set:
Capybara::Screenshot.autosave_on_failure = true
@ndp tried that too.
@zwarburg I ran into this as well and noticed that it seems to only catch feature
specs. I was also using describe, but switching to rspec feature syntax made it work for me.
@zwarburg if you can provide me with a working example i.e. one that I can drop in the Gem, I can see if I can find a more permanent fix or perhaps update the docs to indicate what people should do.
I believe this is working as expected. describe
is part of the RSpec library, not Capybara. That's why Capybara hooks are not being triggered on failures.
If you want a different behavior, you can tag a describe
block with type: :feature
.
describe 'spec', type: :feature do
before(:each) do
@my_page = login_and_open_my_page
end
it "fails" do
expect(5).to eq(6)
end
end
For more information, here's the documentation: https://github.com/teamcapybara/capybara#using-capybara-with-rspec