I’ve implemented screenshot capturing for my automation project using rspec/capybara.
I was expecting capybara to take a screenshot each time a test fails, no matter where it fails (in preconditions or during test execution or in postconditions).
spec_helper has following code:
config.after(:each) do |example|
page.save_screenshot(example.description) if example.exception
end
Majority of spec files have before :context block that executes once for all tests in scope of specific context.
The problem is that in case test fails in before or after :context block, screenshot is not taken. It is taken only in case test fails in ‘it’ block.
I’ve tried adding around :each hook in spec_helper file but it did not help unfortunately.
Here is the example of how it all works for a case screenshot is taken and for a case screenshot is not taken:
screenshot is not taken:
describe 'title', type: :feature do
include_context 'User logged in'
describe 'When user logged in' do
before(:all) { do_something_causing_fail }
it 'Verify something' do
expect(something).to eq something
end
end
end
screenshot is taken:
describe 'title', type: :feature do
include_context 'User logged in'
describe 'When user logged in' do
before(:all) { }
it 'Verify something' do
do_something_causing_fail
expect(something).to eq something
end
end
end
VLAD is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1