Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Screenshots not being auto generated with Ruby-Rspec (no rails) #232

Open
zwarburg opened this issue May 8, 2018 · 5 comments
Open

Screenshots not being auto generated with Ruby-Rspec (no rails) #232

zwarburg opened this issue May 8, 2018 · 5 comments
Labels

Comments

@zwarburg
Copy link

zwarburg commented May 8, 2018

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
@ndp
Copy link

ndp commented May 10, 2018

I have this set:

Capybara::Screenshot.autosave_on_failure = true

@zwarburg
Copy link
Author

@ndp tried that too.

@aterris
Copy link

aterris commented Jun 20, 2018

@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.

@mattheworiordan
Copy link
Owner

@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.

@skmichaelson
Copy link
Contributor

skmichaelson commented Mar 5, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants