Skip to content

Commit 1e573a7

Browse files
authored
fix: #203 lazy create and attach to a page after reset (#260)
* fix: #203 lazy create and attach to a page after reset * fix: linter
1 parent 7f09274 commit 1e573a7

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

lib/capybara/cuprite/browser.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def initialize(options = nil)
1717
@options.url_blacklist = prepare_wildcards(options&.dig(:url_blacklist))
1818
@options.url_whitelist = prepare_wildcards(options&.dig(:url_whitelist))
1919

20-
@page = false
20+
@page = nil
2121
end
2222

2323
def command(...)
@@ -28,20 +28,20 @@ def command(...)
2828
end
2929

3030
def page
31-
raise Ferrum::NoSuchPageError if @page.nil?
31+
raise Ferrum::NoSuchPageError if @page&.closed?
3232

3333
@page ||= attach_page
3434
end
3535

3636
def reset
3737
super
3838
@options.reset_window_size
39-
@page = attach_page
39+
@page = nil
4040
end
4141

4242
def quit
4343
super
44-
@page = false
44+
@page = nil
4545
end
4646

4747
def resize(**options)
@@ -122,7 +122,7 @@ def close_window(target_id)
122122
target = targets[target_id]
123123
raise Ferrum::NoSuchPageError unless target
124124

125-
@page = nil if @page.target_id == target.id
125+
@page = ClosedPage.new if @page.target_id == target.id
126126
target.page.close
127127
targets.delete(target_id) # page.close is async, delete target asap
128128
end

lib/capybara/cuprite/page.rb

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
module Capybara
66
module Cuprite
7+
class ClosedPage
8+
def closed?
9+
true
10+
end
11+
end
12+
713
class Page < Ferrum::Page
814
MODAL_WAIT = ENV.fetch("CUPRITE_MODAL_WAIT", 0.05).to_f
915
TRIGGER_CLICK_WAIT = ENV.fetch("CUPRITE_TRIGGER_CLICK_WAIT", 0.1).to_f
@@ -129,6 +135,10 @@ def title
129135
active_frame.current_title
130136
end
131137

138+
def closed?
139+
false
140+
end
141+
132142
private
133143

134144
def prepare_page

spec/spec_helper.rb

+5
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ module TestSessions
8787
#has_element? should be true if the given element is on the page
8888
REGEXP
8989

90+
intentional_skip = <<~REGEXP.split("\n").map { |s| Regexp.quote(s.strip) }.join("|")
91+
Capybara::Session Cuprite #reset_session! closes extra windows
92+
REGEXP
93+
9094
metadata[:skip] = true if metadata[:full_description].match(/#{regexes}/)
95+
metadata[:skip] = "Intentionally skipped" if metadata[:full_description].match(/#{intentional_skip}/)
9196
metadata[:skip] = true if metadata[:requires]&.include?(:active_element)
9297
end
9398

0 commit comments

Comments
 (0)