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

fix: #203 lazy create and attach to a page after reset #260

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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