cuprite 0.15.1 → 0.17
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 +21 -25
- data/lib/capybara/cuprite/browser.rb +17 -6
- data/lib/capybara/cuprite/cookie.rb +1 -1
- data/lib/capybara/cuprite/driver.rb +4 -31
- data/lib/capybara/cuprite/javascripts/index.js +29 -0
- data/lib/capybara/cuprite/node.rb +9 -3
- data/lib/capybara/cuprite/page.rb +0 -1
- data/lib/capybara/cuprite/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96a5c4e78aa8ea75902caef045651f816880702db158b41d0b4ef3e916bf3611
|
4
|
+
data.tar.gz: 0f9f1ead810f03c6ee4fbe2053ad0e6476c26a4baeb53e2315b7110e47120243
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f2ec852f926cb0e013152c227f0b49973668eb800a7c9dd4192c25d08fb31a3e477218fa5593742229de236bb80f694245648b22ba430fbf6ffa7f54680e1e9
|
7
|
+
data.tar.gz: 2af0ca1ec6e7f83ef1c844fd49340f26716b96cea3cedfffbb1f4cf6744b3825905a44a8f0b33607ce3a588b52046a585a61c349188ec6d0c4c976b0ef76be49
|
data/README.md
CHANGED
@@ -67,18 +67,8 @@ end
|
|
67
67
|
|
68
68
|
## Debugging
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
`page.driver.debug(binding)` in your test to pause it. This will launch the
|
73
|
-
browser where you can inspect the content.
|
74
|
-
|
75
|
-
```ruby
|
76
|
-
Capybara.register_driver :cuprite do |app|
|
77
|
-
Capybara::Cuprite::Driver.new(app, inspector: ENV['INSPECTOR'])
|
78
|
-
end
|
79
|
-
```
|
80
|
-
|
81
|
-
then somewhere in the test:
|
70
|
+
You can put `page.driver.debug` or `page.driver.debug(binding)` in your test to pause it.
|
71
|
+
This will launch the browser where you can inspect the content.
|
82
72
|
|
83
73
|
```ruby
|
84
74
|
it "does something useful" do
|
@@ -122,13 +112,17 @@ be automatically cleared at the end of the test.
|
|
122
112
|
|
123
113
|
## Network traffic
|
124
114
|
|
125
|
-
* `page.driver.network_traffic`
|
126
|
-
the current page. This returns an array of request objects.
|
115
|
+
* `page.driver.network_traffic` allows you to inspect network traffic (i.e., loaded resources) on the current page. It returns an array of `Ferrum::Network::Exchange` objects, each representing a network request/response exchange. You can query both the request and response details of each exchange.
|
127
116
|
|
128
117
|
```ruby
|
129
|
-
|
130
|
-
|
131
|
-
|
118
|
+
# Retrieve all network exchanges
|
119
|
+
network_traffic = page.driver.network_traffic
|
120
|
+
|
121
|
+
# Access the first exchange
|
122
|
+
first_exchange = network_traffic.first
|
123
|
+
|
124
|
+
# Inspect the response of the first request
|
125
|
+
response = first_exchange.response
|
132
126
|
```
|
133
127
|
|
134
128
|
* `page.driver.wait_for_network_idle` Natively waits for network idle and if
|
@@ -183,27 +177,29 @@ Besides capybara screenshot method you can get image as Base64:
|
|
183
177
|
|
184
178
|
## Proxy
|
185
179
|
|
186
|
-
* `page.driver.set_proxy(ip, port,
|
180
|
+
* `page.driver.set_proxy(ip, port, user, password)`
|
187
181
|
|
188
182
|
|
189
|
-
## URL
|
183
|
+
## URL Blocklisting & Allowlisting
|
190
184
|
|
191
|
-
Cuprite supports URL
|
185
|
+
Cuprite supports URL blocklisting, which allows you to prevent scripts from
|
192
186
|
running on designated domains:
|
193
187
|
|
194
188
|
```ruby
|
195
|
-
page.driver.browser.
|
189
|
+
page.driver.browser.url_blocklist = %r{http://www.example.com}
|
196
190
|
```
|
197
191
|
|
198
|
-
and also URL
|
192
|
+
and also URL allowlisting, which allows scripts to only run on designated
|
199
193
|
domains:
|
200
194
|
|
201
195
|
```ruby
|
202
|
-
page.driver.browser.
|
196
|
+
page.driver.browser.url_allowlist = %r{http://www.example.com}
|
203
197
|
```
|
204
198
|
|
205
|
-
|
206
|
-
|
199
|
+
For legacy support, `url_blacklist=` and `url_whitelist=` continue to work respectively.
|
200
|
+
|
201
|
+
If you are experiencing slower run times, consider creating a URL allowlist of
|
202
|
+
domains that are essential or a blocklist of domains that are not essential,
|
207
203
|
such as ad networks or analytics, to your testing environment.
|
208
204
|
|
209
205
|
## License
|
@@ -139,26 +139,33 @@ module Capybara
|
|
139
139
|
raise NotImplementedError
|
140
140
|
end
|
141
141
|
|
142
|
-
def drag(node, other, steps, delay = nil)
|
142
|
+
def drag(node, other, steps, delay = nil, scroll = true)
|
143
143
|
x1, y1 = node.find_position
|
144
|
-
x2, y2 = other.find_position
|
145
144
|
|
146
145
|
mouse.move(x: x1, y: y1)
|
147
146
|
mouse.down
|
148
147
|
sleep delay if delay
|
148
|
+
|
149
|
+
other.scroll_into_view if scroll
|
150
|
+
|
151
|
+
x2, y2 = other.find_position
|
149
152
|
mouse.move(x: x2, y: y2, steps: steps)
|
153
|
+
|
150
154
|
mouse.up
|
151
155
|
end
|
152
156
|
|
153
|
-
def drag_by(node,
|
157
|
+
def drag_by(node, dx, dy, steps, delay = nil, scroll = true)
|
154
158
|
x1, y1 = node.find_position
|
155
|
-
x2 = x1 + x
|
156
|
-
y2 = y1 + y
|
157
159
|
|
158
160
|
mouse.move(x: x1, y: y1)
|
159
161
|
mouse.down
|
162
|
+
|
160
163
|
sleep delay if delay
|
161
|
-
|
164
|
+
|
165
|
+
evaluate("window.scrollBy(#{dx}, #{dy})") if scroll # should be extracted to Mouse#scroll_by in ferrum
|
166
|
+
|
167
|
+
x2, y2 = node.find_position
|
168
|
+
mouse.move(x: x2 + dx, y: y2 + dy, steps: steps)
|
162
169
|
mouse.up
|
163
170
|
end
|
164
171
|
|
@@ -203,6 +210,10 @@ module Capybara
|
|
203
210
|
evaluate_on(node: node, expression: "_cuprite.path(this)")
|
204
211
|
end
|
205
212
|
|
213
|
+
def obscured?(node)
|
214
|
+
evaluate_on(node: node, expression: "_cuprite.isObscured(this)")
|
215
|
+
end
|
216
|
+
|
206
217
|
def all_text(node)
|
207
218
|
node.text
|
208
219
|
end
|
@@ -251,7 +251,8 @@ module Capybara
|
|
251
251
|
|
252
252
|
def remove_cookie(name, **options)
|
253
253
|
options[:domain] = default_domain if options.empty?
|
254
|
-
|
254
|
+
options = options.merge(name: name)
|
255
|
+
browser.cookies.remove(**options)
|
255
256
|
end
|
256
257
|
|
257
258
|
def clear_cookies
|
@@ -273,32 +274,8 @@ module Capybara
|
|
273
274
|
end
|
274
275
|
alias authorize basic_authorize
|
275
276
|
|
276
|
-
def
|
277
|
-
|
278
|
-
|
279
|
-
devtools_frontend_path = response[0]&.[]("devtoolsFrontendUrl")
|
280
|
-
raise "Could not generate debug url for remote debugging session" unless devtools_frontend_path
|
281
|
-
|
282
|
-
build_remote_debug_url(path: devtools_frontend_path)
|
283
|
-
end
|
284
|
-
|
285
|
-
def debug(binding = nil)
|
286
|
-
if @options[:inspector]
|
287
|
-
Process.spawn(browser.process.path, debug_url)
|
288
|
-
|
289
|
-
if binding.respond_to?(:pry)
|
290
|
-
Pry.start(binding)
|
291
|
-
elsif binding.respond_to?(:irb)
|
292
|
-
binding.irb
|
293
|
-
else
|
294
|
-
pause
|
295
|
-
end
|
296
|
-
else
|
297
|
-
raise Error, "To use the remote debugging, you have to launch " \
|
298
|
-
"the driver with `inspector: ENV['INSPECTOR']` " \
|
299
|
-
"configuration option and run your test suite passing " \
|
300
|
-
"env variable"
|
301
|
-
end
|
277
|
+
def debug(...)
|
278
|
+
browser.debug(...)
|
302
279
|
end
|
303
280
|
|
304
281
|
def pause
|
@@ -377,10 +354,6 @@ module Capybara
|
|
377
354
|
|
378
355
|
private
|
379
356
|
|
380
|
-
def build_remote_debug_url(path:)
|
381
|
-
"http://#{browser.process.host}:#{browser.process.port}#{path}"
|
382
|
-
end
|
383
|
-
|
384
357
|
def default_domain
|
385
358
|
if @started
|
386
359
|
URI.parse(browser.current_url).host
|
@@ -115,6 +115,35 @@ class Cuprite {
|
|
115
115
|
return `//${selectors.join("/")}`;
|
116
116
|
}
|
117
117
|
|
118
|
+
/**
|
119
|
+
* Returns true if the node is obscured in the viewport.
|
120
|
+
*
|
121
|
+
* @param {Element} node
|
122
|
+
* @return {boolean} true if the node is obscured, false otherwise
|
123
|
+
*/
|
124
|
+
isObscured(node) {
|
125
|
+
let win = window;
|
126
|
+
let rect = node.getBoundingClientRect();
|
127
|
+
let px = rect.left + rect.width / 2;
|
128
|
+
let py = rect.top + rect.height / 2;
|
129
|
+
|
130
|
+
while (win) {
|
131
|
+
let topNode = win.document.elementFromPoint(px, py);
|
132
|
+
|
133
|
+
if (node !== topNode && !node.contains(topNode)) return true;
|
134
|
+
|
135
|
+
node = win.frameElement;
|
136
|
+
if (!node) return false;
|
137
|
+
|
138
|
+
rect = node.getBoundingClientRect();
|
139
|
+
px = rect.left + px;
|
140
|
+
py = rect.top + py;
|
141
|
+
win = win.parent;
|
142
|
+
}
|
143
|
+
|
144
|
+
return false;
|
145
|
+
}
|
146
|
+
|
118
147
|
set(node, value) {
|
119
148
|
if (node.readOnly) return;
|
120
149
|
|
@@ -110,7 +110,7 @@ module Capybara
|
|
110
110
|
command(:set, value.to_s)
|
111
111
|
elsif self[:isContentEditable]
|
112
112
|
command(:delete_text)
|
113
|
-
|
113
|
+
click.type(value.to_s)
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
@@ -161,14 +161,16 @@ module Capybara
|
|
161
161
|
|
162
162
|
def drag_to(other, **options)
|
163
163
|
options[:steps] ||= 1
|
164
|
+
options[:scroll] = true unless options.key?(:scroll)
|
164
165
|
|
165
|
-
command(:drag, other.node, options[:steps], options[:delay])
|
166
|
+
command(:drag, other.node, options[:steps], options[:delay], options[:scroll])
|
166
167
|
end
|
167
168
|
|
168
169
|
def drag_by(x, y, **options)
|
169
170
|
options[:steps] ||= 1
|
171
|
+
options[:scroll] = true unless options.key?(:scroll)
|
170
172
|
|
171
|
-
command(:drag_by, x, y, options[:steps], options[:delay])
|
173
|
+
command(:drag_by, x, y, options[:steps], options[:delay], options[:scroll])
|
172
174
|
end
|
173
175
|
|
174
176
|
def trigger(event)
|
@@ -211,6 +213,10 @@ module Capybara
|
|
211
213
|
command(:path)
|
212
214
|
end
|
213
215
|
|
216
|
+
def obscured?
|
217
|
+
command(:obscured?)
|
218
|
+
end
|
219
|
+
|
214
220
|
def inspect
|
215
221
|
%(#<#{self.class} @node=#{@node.inspect}>)
|
216
222
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cuprite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.17'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Vorotilin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.17.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.17.0
|
41
41
|
description: Cuprite is a driver for Capybara that allows you to run your tests on
|
42
42
|
a headless Chrome browser
|
43
43
|
email:
|
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
requirements: []
|
85
|
-
rubygems_version: 3.5.
|
85
|
+
rubygems_version: 3.5.22
|
86
86
|
signing_key:
|
87
87
|
specification_version: 4
|
88
88
|
summary: Headless Chrome driver for Capybara
|