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

WARN: Screenshot could not be saved. page.current_path is empty #277

Open
MunimIftikhar opened this issue Jan 28, 2021 · 4 comments
Open

Comments

@MunimIftikhar
Copy link

MunimIftikhar commented Jan 28, 2021

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

require "rails_helper"

RSpec.describe "adding a new task" do
  let!(:project) { create(:project, name: "Project Bluebook") }
  let!(:task_1) { create(
    :task, project: project, title: "Search Sky", size: 1, project_order: 1) }
  let!(:task_2) { create(
    :task, project: project, title: "Use Telescope", size: 1,
           project_order: 2) }
  let!(:task_3) { create(
    :task, project: project, title: "Take Notes", size: 1,
           project_order: 3) }

  it "can re-order a task", :js do
    visit(project_path(project))
    find("#task_3")
    within("#task_3") do
      click_on("Up")
    end
    expect(page).to have_selector(
      "tbody:nth-child(2) .name", text: "Take Notes")
      #END:P1
      #START:P2
    visit(project_path(project))
    find("#task_2")
    within("#task_2") do
      expect(page).to have_selector(".name", text: "Take Notes")
    end
  end

end
@MunimIftikhar MunimIftikhar changed the title Failure/Error: expect(page).to have_selector(".name", text: "Take Notes") WARN: Screenshot could not be saved. page.current_path is empty Jan 29, 2021
@christianhellsten
Copy link

"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?

@westonganger
Copy link

westonganger commented Mar 1, 2021

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.

@dacook
Copy link

dacook commented Feb 17, 2022

This is a continuation of this thread: #243

@dacook
Copy link

dacook commented Feb 17, 2022

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.

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

No branches or pull requests

4 participants