Skip to content

Commit

Permalink
fix: #203 lazy create and attach to a page after reset (#260)
Browse files Browse the repository at this point in the history
* fix: #203 lazy create and attach to a page after reset

* fix: linter
  • Loading branch information
route authored Feb 19, 2024
1 parent 7f09274 commit 1e573a7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/capybara/cuprite/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(...)
Expand All @@ -28,20 +28,20 @@ def command(...)
end

def page
raise Ferrum::NoSuchPageError if @page.nil?
raise Ferrum::NoSuchPageError if @page&.closed?

@page ||= attach_page
end

def reset
super
@options.reset_window_size
@page = attach_page
@page = nil
end

def quit
super
@page = false
@page = nil
end

def resize(**options)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions lib/capybara/cuprite/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -129,6 +135,10 @@ def title
active_frame.current_title
end

def closed?
false
end

private

def prepare_page
Expand Down
5 changes: 5 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 1e573a7

Please sign in to comment.