Open MunimIftikhar opened 3 years ago
"WARN: Screenshot could not be saved. page.current_path is empty" is an indication that the browser has yet to load a page. Are you sure the page has loaded?
I was also getting this warning. I noticed that the screenshots are actually getting saved despite what the error says.
To work around this I have added the following monkey patch.
Capybara::Screenshot::Saver.class_eval do
def save
current_path do |path|
if path.empty?
next ### CUSTOM
#warn 'WARN: Screenshot could not be saved. `page.current_path` is empty.'
else
begin
save_html if @html_save
rescue StandardError => e
warn "WARN: HTML source could not be saved. An exception is raised: #{e.inspect}."
end
begin
save_screenshot
rescue StandardError => e
warn "WARN: Screenshot could not be saved. An exception is raised: #{e.inspect}."
end
end
end
end
end
I think that likely an official fix is due here.
This is a continuation of this thread: https://github.com/mattheworiordan/capybara-screenshot/issues/243
It looks like this warning occurs due to multiple problems. In my case, it is not saving the screenshots as @westonganger suggests above, so that fix doesn't help me.
GalenkoEugene's comment helped me discover that my problem was caused by Capybara.reset_sessions! in an rspec after
hook, but that fix doesn't apply as I'm not using the retry gem (maybe I should..). I guess the browser 'window' is closed before this gem has a chance to take the screenshot.
I found in my case reset_sessions
was intended to clear cookies, so I've replaced it with a more direct method to do that (thanks makandra) and it seems to be working! For those looking for code to try out:
# Delete cookies after all responses have completed
config.after(:each, js: true) do
RackRequestBlocker.wait_for_requests_complete
# Capybara.reset_sessions! # <- that was too extreme, let's try a gentler method:
Capybara.current_session.driver.browser.manage.delete_all_cookies # Delete cookies with Selenium
end
So it seems this is often due to conflicting configuration. I don't know enough to be able to suggest how it could be generally resolved.
I'm running the test using
bundle exec rspec
, which gives me the error of:WARN: Screenshot could not be saved. page.current_path is empty
. also getting this error:Failure/Error: expect(page).to have_selector(".name", text: "Take Notes")
. Here's the test I'm trying to test:/spec/system/add_task_spec.rb