cuprite 0.20.1 → 0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +35 -31
- data/lib/capybara/cuprite/deprecation.rb +8 -1
- data/lib/capybara/cuprite/devices.rb +8 -0
- data/lib/capybara/cuprite/driver/deprecations.rb +22 -184
- data/lib/capybara/cuprite/driver/extensions.rb +50 -0
- data/lib/capybara/cuprite/driver/settings.rb +102 -0
- data/lib/capybara/cuprite/driver/window/frames.rb +35 -0
- data/lib/capybara/cuprite/driver/window/modals.rb +113 -0
- data/lib/capybara/cuprite/driver/window.rb +34 -0
- data/lib/capybara/cuprite/driver/windows.rb +90 -0
- data/lib/capybara/cuprite/driver.rb +331 -66
- data/lib/capybara/cuprite/errors.rb +48 -1
- data/lib/capybara/cuprite/finder/hints.rb +51 -0
- data/lib/capybara/cuprite/finder.rb +18 -3
- data/lib/capybara/cuprite/javascripts/index.js +123 -58
- data/lib/capybara/cuprite/node/extensions.rb +14 -4
- data/lib/capybara/cuprite/node/typing.rb +75 -0
- data/lib/capybara/cuprite/node.rb +208 -63
- data/lib/capybara/cuprite/version.rb +3 -1
- data/lib/capybara/cuprite.rb +1 -4
- data/sig/capybara/cuprite/deprecation.rbs +7 -0
- data/sig/capybara/cuprite/devices.rbs +19 -0
- data/sig/capybara/cuprite/driver/deprecations.rbs +11 -0
- data/sig/capybara/cuprite/driver/extensions.rbs +29 -0
- data/sig/capybara/cuprite/driver/settings.rbs +42 -0
- data/sig/capybara/cuprite/driver/window/frames.rbs +13 -0
- data/sig/capybara/cuprite/driver/window/modals.rbs +29 -0
- data/sig/capybara/cuprite/driver/window.rbs +22 -0
- data/sig/capybara/cuprite/driver/windows.rbs +27 -0
- data/sig/capybara/cuprite/driver.rbs +140 -0
- data/sig/capybara/cuprite/errors.rbs +56 -0
- data/sig/capybara/cuprite/finder/hints.rbs +28 -0
- data/sig/capybara/cuprite/finder.rbs +7 -0
- data/sig/capybara/cuprite/node/extensions.rbs +9 -0
- data/sig/capybara/cuprite/node/typing.rbs +30 -0
- data/sig/capybara/cuprite/node.rbs +112 -0
- data/sig/capybara/cuprite/version.rbs +5 -0
- metadata +27 -11
- data/lib/capybara/cuprite/browser/deprecations.rb +0 -26
- data/lib/capybara/cuprite/browser/extensions.rb +0 -59
- data/lib/capybara/cuprite/browser.rb +0 -108
- data/lib/capybara/cuprite/node/deprecations.rb +0 -43
- data/lib/capybara/cuprite/options.rb +0 -33
- data/lib/capybara/cuprite/page/frames.rb +0 -47
- data/lib/capybara/cuprite/page/modals.rb +0 -118
- data/lib/capybara/cuprite/page.rb +0 -36
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "capybara/cuprite/browser/deprecations"
|
|
4
|
-
require "capybara/cuprite/browser/extensions"
|
|
5
|
-
|
|
6
|
-
module Capybara
|
|
7
|
-
module Cuprite
|
|
8
|
-
class Browser < Ferrum::Browser
|
|
9
|
-
include Deprecations
|
|
10
|
-
include Extensions
|
|
11
|
-
|
|
12
|
-
def initialize(options = nil)
|
|
13
|
-
device = options&.dig(:emulate)
|
|
14
|
-
options = Devices.fetch(device).except(:user_agent).merge(options) if device
|
|
15
|
-
super
|
|
16
|
-
|
|
17
|
-
@options.raise_on_unhandled_modal = options&.dig(:raise_on_unhandled_modal)
|
|
18
|
-
@options.url_blacklist = prepare_wildcards(options&.dig(:url_blacklist))
|
|
19
|
-
@options.url_whitelist = prepare_wildcards(options&.dig(:url_whitelist))
|
|
20
|
-
|
|
21
|
-
@page = nil
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def command(...)
|
|
25
|
-
super
|
|
26
|
-
rescue Ferrum::DeadBrowserError
|
|
27
|
-
restart
|
|
28
|
-
raise
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def page
|
|
32
|
-
raise Ferrum::NoSuchPageError if @page_closed
|
|
33
|
-
|
|
34
|
-
@page ||= attach_page
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def reset
|
|
38
|
-
super
|
|
39
|
-
ensure
|
|
40
|
-
@options.reset_window_size
|
|
41
|
-
forget_page
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def quit
|
|
45
|
-
super
|
|
46
|
-
forget_page
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def resize(**options)
|
|
50
|
-
@options.window_size = [options[:width], options[:height]]
|
|
51
|
-
super
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def current_window_handle
|
|
55
|
-
page.target_id
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def window_handles
|
|
59
|
-
targets.values.select(&:page?).map(&:id)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def open_new_window
|
|
63
|
-
attach_page(default_context.create_target.id)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def switch_to_window(target_id)
|
|
67
|
-
target = window_target(target_id)
|
|
68
|
-
forget_page
|
|
69
|
-
@page = attach_page(target.id)
|
|
70
|
-
@page.activate
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def close_window(target_id)
|
|
74
|
-
target = window_target(target_id)
|
|
75
|
-
if @page&.target_id == target.id
|
|
76
|
-
forget_page
|
|
77
|
-
@page_closed = true
|
|
78
|
-
end
|
|
79
|
-
target.page.close
|
|
80
|
-
targets.delete(target_id) # page.close is async, delete target asap
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
private
|
|
84
|
-
|
|
85
|
-
def forget_page
|
|
86
|
-
@page = nil
|
|
87
|
-
@page_closed = false
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def window_target(target_id)
|
|
91
|
-
target = targets[target_id]
|
|
92
|
-
raise Ferrum::NoSuchPageError unless target&.page?
|
|
93
|
-
|
|
94
|
-
target
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def attach_page(target_id = nil)
|
|
98
|
-
target = targets[target_id] if target_id
|
|
99
|
-
target ||= default_context.default_target
|
|
100
|
-
return target.page if target.connected?
|
|
101
|
-
|
|
102
|
-
target.maybe_sleep_if_new_window
|
|
103
|
-
target.page = Page.new(target.client, context_id: target.context_id, target_id: target.id)
|
|
104
|
-
target.page
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
end
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "capybara/cuprite/deprecation"
|
|
4
|
-
|
|
5
|
-
module Capybara
|
|
6
|
-
module Cuprite
|
|
7
|
-
class Node < Capybara::Driver::Node
|
|
8
|
-
module Deprecations
|
|
9
|
-
def browser
|
|
10
|
-
Cuprite.deprecation_warning("#{self.class}#browser", "use page.driver.browser")
|
|
11
|
-
driver.browser
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def parents
|
|
15
|
-
Cuprite.deprecation_warning("#{self.class}#parents", "use Capybara's ancestor")
|
|
16
|
-
command { driver.browser.evaluate("_cuprite.parents(node)", node: node) }.map do |parent|
|
|
17
|
-
self.class.new(driver, parent)
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def property(name)
|
|
22
|
-
Cuprite.deprecation_warning("#{self.class}#property", "use node.native.node.property")
|
|
23
|
-
command { node.property(name) }
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def attributes
|
|
27
|
-
Cuprite.deprecation_warning("#{self.class}#attributes")
|
|
28
|
-
JSON.parse(command(:getAttributes))
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def description
|
|
32
|
-
Cuprite.deprecation_warning("#{self.class}#description", "use node.native.node.description")
|
|
33
|
-
node.description
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def send_key(*keys)
|
|
37
|
-
Cuprite.deprecation_warning("#{self.class}#send_key", "use #send_keys")
|
|
38
|
-
send_keys(*keys)
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Ferrum
|
|
4
|
-
class Browser
|
|
5
|
-
class Options
|
|
6
|
-
attr_writer :window_size
|
|
7
|
-
attr_accessor :url_blacklist, :url_whitelist, :raise_on_unhandled_modal
|
|
8
|
-
|
|
9
|
-
def mobile
|
|
10
|
-
@options.fetch(:mobile, nil)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def scale_factor
|
|
14
|
-
@options.fetch(:scale_factor, 0)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def device_user_agent
|
|
18
|
-
Capybara::Cuprite::Devices.fetch(@options[:emulate])[:user_agent] if @options[:emulate]
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def default_user_agent
|
|
22
|
-
return @default_user_agent unless device_user_agent
|
|
23
|
-
|
|
24
|
-
chrome_version = @default_user_agent.to_s[%r{Chrome/(\S+)}, 1].to_s
|
|
25
|
-
format(device_user_agent, version: chrome_version)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def reset_window_size
|
|
29
|
-
@window_size = @options[:window_size]
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "forwardable"
|
|
4
|
-
|
|
5
|
-
module Capybara
|
|
6
|
-
module Cuprite
|
|
7
|
-
class Page < Ferrum::Page
|
|
8
|
-
module Frames
|
|
9
|
-
extend Forwardable
|
|
10
|
-
|
|
11
|
-
delegate %i[at_css at_xpath css xpath
|
|
12
|
-
current_url current_title body execution_id execution_id!
|
|
13
|
-
evaluate execute] => :active_frame
|
|
14
|
-
|
|
15
|
-
def initialize(...)
|
|
16
|
-
@frame_stack = []
|
|
17
|
-
super
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def switch_to_frame(handle)
|
|
21
|
-
case handle
|
|
22
|
-
when :parent
|
|
23
|
-
@frame_stack.pop
|
|
24
|
-
when :top
|
|
25
|
-
@frame_stack = []
|
|
26
|
-
else
|
|
27
|
-
@frame_stack << handle
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def title
|
|
32
|
-
active_frame.current_title
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
private
|
|
36
|
-
|
|
37
|
-
def active_frame
|
|
38
|
-
if @frame_stack.empty?
|
|
39
|
-
main_frame
|
|
40
|
-
else
|
|
41
|
-
@frames[@frame_stack.last]
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Capybara
|
|
4
|
-
module Cuprite
|
|
5
|
-
class Page < Ferrum::Page
|
|
6
|
-
module Modals
|
|
7
|
-
MODAL_WAIT = ENV.fetch("CUPRITE_MODAL_WAIT", 0.05).to_f
|
|
8
|
-
|
|
9
|
-
def initialize(...)
|
|
10
|
-
@accept_modal = []
|
|
11
|
-
@modal_messages = []
|
|
12
|
-
@modal_response = nil
|
|
13
|
-
@unhandled_modal_error = nil
|
|
14
|
-
super
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# The `Page.javascriptDialogOpening` event is handled on Ferrum's
|
|
18
|
-
# background CDP dispatcher thread, so raising there wouldn't reach
|
|
19
|
-
# the caller and would permanently kill that thread instead. The
|
|
20
|
-
# dialog is always accepted immediately from that thread, and the
|
|
21
|
-
# error (if any) is stashed here to be raised from the main thread
|
|
22
|
-
# the next time it makes a command round trip.
|
|
23
|
-
def command(...)
|
|
24
|
-
raise_pending_unhandled_modal_error! { super }
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def accept_confirm
|
|
28
|
-
@accept_modal << true
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def dismiss_confirm
|
|
32
|
-
@accept_modal << false
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def accept_prompt(modal_response)
|
|
36
|
-
@accept_modal << true
|
|
37
|
-
@modal_response = modal_response
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def dismiss_prompt
|
|
41
|
-
@accept_modal << false
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def find_modal(options)
|
|
45
|
-
start = Ferrum::Utils::ElapsedTime.monotonic_time
|
|
46
|
-
expect_text = options[:text]
|
|
47
|
-
expect_regexp = expect_text.is_a?(Regexp) ? expect_text : Regexp.escape(expect_text.to_s)
|
|
48
|
-
not_found_msg = "Unable to find modal dialog"
|
|
49
|
-
not_found_msg += " with #{expect_text}" if expect_text
|
|
50
|
-
wait = options.fetch(:wait, timeout)
|
|
51
|
-
|
|
52
|
-
begin
|
|
53
|
-
modal_text = @modal_messages.shift
|
|
54
|
-
raise Capybara::ModalNotFound if modal_text.nil? || (expect_text && !modal_text.match(expect_regexp))
|
|
55
|
-
rescue Capybara::ModalNotFound => e
|
|
56
|
-
raise e, not_found_msg if Ferrum::Utils::ElapsedTime.timeout?(start, wait)
|
|
57
|
-
|
|
58
|
-
sleep(MODAL_WAIT)
|
|
59
|
-
retry
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
modal_text
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
private
|
|
66
|
-
|
|
67
|
-
def raise_pending_unhandled_modal_error!
|
|
68
|
-
error = @unhandled_modal_error
|
|
69
|
-
@unhandled_modal_error = nil
|
|
70
|
-
raise error if error
|
|
71
|
-
|
|
72
|
-
yield
|
|
73
|
-
ensure
|
|
74
|
-
error = @unhandled_modal_error
|
|
75
|
-
@unhandled_modal_error = nil
|
|
76
|
-
raise error if error
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def prepare_page
|
|
80
|
-
super
|
|
81
|
-
on("Page.javascriptDialogOpening") { |params| handle_javascript_dialog(params) }
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def handle_javascript_dialog(params)
|
|
85
|
-
accept_modal = @accept_modal.last
|
|
86
|
-
unhandled_modal_error = nil
|
|
87
|
-
|
|
88
|
-
if [true, false].include?(accept_modal)
|
|
89
|
-
@accept_modal.pop
|
|
90
|
-
@modal_messages << params["message"]
|
|
91
|
-
options = { accept: accept_modal }
|
|
92
|
-
response = @modal_response || params["defaultPrompt"]
|
|
93
|
-
else
|
|
94
|
-
with_text = params["message"] ? "with text `#{params['message']}` " : ""
|
|
95
|
-
message = "Modal window #{with_text}has been opened, but you didn't wrap " \
|
|
96
|
-
"your code into (`accept_prompt` | `dismiss_prompt` | " \
|
|
97
|
-
"`accept_confirm` | `dismiss_confirm` | `accept_alert`), " \
|
|
98
|
-
"accepting by default"
|
|
99
|
-
|
|
100
|
-
if @options.raise_on_unhandled_modal
|
|
101
|
-
unhandled_modal_error = UnhandledModalError.new(message)
|
|
102
|
-
else
|
|
103
|
-
warn message
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
options = { accept: true }
|
|
107
|
-
response = params["defaultPrompt"]
|
|
108
|
-
end
|
|
109
|
-
options.merge!(promptText: response) if response
|
|
110
|
-
# Skips #command so a pending error isn't raised on the dispatcher thread.
|
|
111
|
-
client.command("Page.handleJavaScriptDialog", timeout: timeout, **options)
|
|
112
|
-
|
|
113
|
-
@unhandled_modal_error = unhandled_modal_error if unhandled_modal_error
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
end
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "capybara/cuprite/page/frames"
|
|
4
|
-
require "capybara/cuprite/page/modals"
|
|
5
|
-
|
|
6
|
-
module Capybara
|
|
7
|
-
module Cuprite
|
|
8
|
-
class Page < Ferrum::Page
|
|
9
|
-
EXTENSION_JS = File.read(Driver::EXTENSION).freeze
|
|
10
|
-
|
|
11
|
-
include Frames
|
|
12
|
-
include Modals
|
|
13
|
-
|
|
14
|
-
def set_viewport(width: 0, height: 0, scale_factor: @options.scale_factor, mobile: @options.mobile)
|
|
15
|
-
super
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
private
|
|
19
|
-
|
|
20
|
-
def prepare_page
|
|
21
|
-
super
|
|
22
|
-
execute(EXTENSION_JS)
|
|
23
|
-
|
|
24
|
-
width, height = @options.window_size
|
|
25
|
-
width && height ? resize(width: width, height: height) : set_viewport
|
|
26
|
-
command("Network.setUserAgentOverride", userAgent: default_user_agent) if @options.device_user_agent
|
|
27
|
-
|
|
28
|
-
if @options.url_blacklist.any?
|
|
29
|
-
network.blacklist = @options.url_blacklist
|
|
30
|
-
elsif @options.url_whitelist.any?
|
|
31
|
-
network.whitelist = @options.url_whitelist
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|