diff --git a/lib/capybara/cuprite/browser.rb b/lib/capybara/cuprite/browser.rb index 1b6da63..a893b07 100644 --- a/lib/capybara/cuprite/browser.rb +++ b/lib/capybara/cuprite/browser.rb @@ -17,7 +17,7 @@ def initialize(options = nil) @options.url_blacklist = prepare_wildcards(options&.dig(:url_blacklist)) @options.url_whitelist = prepare_wildcards(options&.dig(:url_whitelist)) - @page = false + @page = nil end def command(...) @@ -28,7 +28,7 @@ def command(...) end def page - raise Ferrum::NoSuchPageError if @page.nil? + raise Ferrum::NoSuchPageError if @page&.closed? @page ||= attach_page end @@ -36,12 +36,12 @@ def page def reset super @options.reset_window_size - @page = attach_page + @page = nil end def quit super - @page = false + @page = nil end def resize(**options) @@ -122,7 +122,7 @@ def close_window(target_id) target = targets[target_id] raise Ferrum::NoSuchPageError unless target - @page = nil if @page.target_id == target.id + @page = ClosedPage.new if @page.target_id == target.id target.page.close targets.delete(target_id) # page.close is async, delete target asap end diff --git a/lib/capybara/cuprite/page.rb b/lib/capybara/cuprite/page.rb index 7d5b1f7..f0a922b 100644 --- a/lib/capybara/cuprite/page.rb +++ b/lib/capybara/cuprite/page.rb @@ -4,6 +4,12 @@ module Capybara module Cuprite + class ClosedPage + def closed? + true + end + end + class Page < Ferrum::Page MODAL_WAIT = ENV.fetch("CUPRITE_MODAL_WAIT", 0.05).to_f TRIGGER_CLICK_WAIT = ENV.fetch("CUPRITE_TRIGGER_CLICK_WAIT", 0.1).to_f @@ -129,6 +135,10 @@ def title active_frame.current_title end + def closed? + false + end + private def prepare_page diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c8f8246..19fef2e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -87,7 +87,12 @@ module TestSessions #has_element? should be true if the given element is on the page REGEXP + intentional_skip = <<~REGEXP.split("\n").map { |s| Regexp.quote(s.strip) }.join("|") + Capybara::Session Cuprite #reset_session! closes extra windows + REGEXP + metadata[:skip] = true if metadata[:full_description].match(/#{regexes}/) + metadata[:skip] = "Intentionally skipped" if metadata[:full_description].match(/#{intentional_skip}/) metadata[:skip] = true if metadata[:requires]&.include?(:active_element) end