-
Notifications
You must be signed in to change notification settings - Fork 168
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
Automatic screenshot capture not working with rspec-steps #158
Comments
I guess this is more of a feature request than a bug, as rspec-steps isn't officially supported by capybara-screenshot In any case, here's what I have managed to find out: It seems that rspec-steps is using Thank you! |
Ran into this problem as well |
Dug into this and it seems more of an issue with rspec-steps than capybara-screenshot.
For example, with the following spec: require 'capybara'
require 'capybara/rspec'
require 'capybara/poltergeist'
require 'capybara-screenshot/rspec'
require 'rspec-steps'
require 'pry'
Capybara.configure do |c|
c.javascript_driver = :poltergeist
c.run_server = false
c.app_host = 'http://app.lvh.me:3000'
end
RSpec::Steps.steps 'Smoke Tests', type: :feature, js: true do
it 'Can visit page' do
visit '/'
end
it 'Can do stuff' do
binding.pry
click_on 'Break test with nonexistant button'
expect(page).to have_current_path('done')
end
it 'Can do more stuff' do
visit '/'
end
end When we hit 18: end
19:
20: it 'Can do stuff' do
21: binding.pry
=> 22: click_on 'Break test with nonexistant button'
23:
24: expect(page).to have_current_path('done')
25: end
26: it 'Can do more stuff' do
[2] pry(#<RSpec::ExampleGroups::SmokeTests>)> RSpec.current_example
=> #<RSpec::Core::Example "Can visit page"> This propagates itself into 52: def after_failed_example(example)
53: if example.example_group.include?(Capybara::DSL) # Capybara DSL method has been included for a feature we can snapshot
54: Capybara.using_session(Capybara::Screenshot.final_session_name) do
55: require 'pry'
56: binding.pry
=> 57: if Capybara.page.current_url != '' && Capybara::Screenshot.autosave_on_failure && example.exception
58: filename_prefix = Capybara::Screenshot.filename_prefix_for(:rspec, example)
59:
60: saver = Capybara::Screenshot.new_saver(Capybara, Capybara.page, true, filename_prefix)
61: saver.save
62:
63: example.metadata[:screenshot] = {}
64: example.metadata[:screenshot][:html] = saver.html_path if saver.html_saved?
65: example.metadata[:screenshot][:image] = saver.screenshot_path if saver.screenshot_saved?
66: end
67: end
68: end
69: end
[1] pry(Capybara::Screenshot::RSpec)> example
=> #<RSpec::Core::Example "Can visit page">
[2] pry(Capybara::Screenshot::RSpec)> example.exception
=> nil And we see that |
@optix2000 thanks for the analysis. I am not familiar with RSpec steps, but I assume it must expose an API to access the step exceptions? If so, do you fancy suggesting a fix with a PR perhaps? |
Hey @mattheworiordan, From my cursory read of rspec-steps, I can't seem to find any API to access the actual steps, or their exceptions, so it may be non-trivial to work around this in capybara-screenshot. Unfortunately, I don't think I'll have the time, nor am I familiar enough with RSpec to fix the issue in rspec-steps. |
Ok, that's a shame. Well if you think this becomes a big enough problem for yourself, hopefully you'll find the time and be able to make an open source contribution to this gem. I'd be very grateful, as I am sure everyone using |
I may consider it as I get more familiar with Ruby and RSpec, though as it is now, everything is too magic. I did write up a quick alternative that approximates rspec-steps available here: |
Hello there,
I am doing some smoke testing and I use rspec-steps with capybara and poltergeist.
When running the tests I found out that automatic screenshot feature only works for the first step definition, for all others I get no screenshot.
Code:
If I move the
expect(page). to have_css '#some-non-existant-element'
line to the first block, right aftervisit(site_url)
it works just fine.Cmd output with a run which doesn't generate a screenshot:
Am I doing something wrong?
Thank you
The text was updated successfully, but these errors were encountered: