cuprite 0.9 → 0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +92 -84
- data/lib/capybara/cuprite/driver.rb +20 -5
- data/lib/capybara/cuprite/node.rb +11 -8
- data/lib/capybara/cuprite/page.rb +8 -3
- 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: 7101647cda6595d4d7644edf51bf61fb4891d2afaaa8eb51e04a1a10f587433f
|
4
|
+
data.tar.gz: bcfefe534e782ab4083068d9b6b0643183a5be8ea5f7dcd273b3121b8e790ede
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae72432731e273f9c59df718a31d66fb82678bd07ab45cb717d931704b20847253c7221a6cbda8dcb7468be0042ca74d0d96a3e11c9b6d63fbf2dc1eec8cb8ec
|
7
|
+
data.tar.gz: 747ff03cc544263579338c4fc389c6b96d39a8634dcaeaf30051713d195119a06c87557fea98e436c9a5748fd980628e8399ff3fba1a82ebaf791a60c4c2a453
|
data/README.md
CHANGED
@@ -1,26 +1,27 @@
|
|
1
|
-
# Cuprite - Headless Chrome driver for Capybara
|
1
|
+
# Cuprite - Headless Chrome driver for Capybara
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/
|
3
|
+
[![Build Status](https://travis-ci.org/rubycdp/cuprite.svg?branch=master)](https://travis-ci.org/rubycdp/cuprite)
|
4
4
|
|
5
|
-
Cuprite is a pure Ruby driver (read as _no_
|
6
|
-
|
7
|
-
you to run
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
Cuprite is a pure Ruby driver (read as _no_ Selenium/WebDriver/ChromeDriver
|
6
|
+
dependency) for [Capybara](https://github.com/teamcapybara/capybara). It allows
|
7
|
+
you to run Capybara tests on a headless Chrome or Chromium. Under the hood it
|
8
|
+
uses [Ferrum](https://github.com/rubycdp/ferrum#index) which is high-level API
|
9
|
+
to the browser by CDP protocol. The design of the driver is as close to
|
10
|
+
[Poltergeist](https://github.com/teampoltergeist/poltergeist) as possible though
|
11
|
+
it's not a goal.
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
consistent design with other browsers. The design of the driver will be as
|
15
|
-
close to [Poltergeist](https://github.com/teampoltergeist/poltergeist) as
|
16
|
-
possible though it's not a goal.
|
13
|
+
[Cuprite](https://evrone.com/cuprite) designed & supported by [Evrone](https://evrone.com/)
|
14
|
+
What else we build [with Ruby](https://evrone.com/ruby)
|
17
15
|
|
18
|
-
## Install ##
|
19
16
|
|
20
|
-
|
17
|
+
## Install
|
18
|
+
|
19
|
+
Add this to your `Gemfile` and run `bundle install`.
|
21
20
|
|
22
21
|
``` ruby
|
23
|
-
|
22
|
+
group :test do
|
23
|
+
gem "cuprite"
|
24
|
+
end
|
24
25
|
```
|
25
26
|
|
26
27
|
In your test setup add:
|
@@ -33,21 +34,31 @@ Capybara.register_driver(:cuprite) do |app|
|
|
33
34
|
end
|
34
35
|
```
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
if you use `Docker` don't forget to pass `no-sandbox` option:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
Capybara::Cuprite::Driver.new(app, browser_options: { 'no-sandbox': nil })
|
41
|
+
```
|
42
|
+
|
43
|
+
Since Cuprite uses [Ferrum](https://github.com/rubycdp/ferrum#examples) there
|
44
|
+
are many useful methods you can call even using this driver:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
browser = page.driver.browser
|
48
|
+
browser.mouse.move(x: 123, y: 456).down.up
|
49
|
+
```
|
50
|
+
|
51
|
+
If you already have tests on Poltergeist then it should simply work, for
|
52
|
+
Selenium you better check your code for `manage` calls because it works
|
53
|
+
differently in Cuprite, see the documentation below.
|
39
54
|
|
40
|
-
## Install Chrome ##
|
41
55
|
|
42
|
-
|
43
|
-
way because it either will be outdated or unofficial, both are bad. Download it
|
44
|
-
from official [source](https://www.chromium.org/getting-involved/download-chromium).
|
45
|
-
Chrome binary should be in the `PATH` or `BROWSER_PATH` or you can pass it as an
|
46
|
-
option
|
56
|
+
## Customization
|
47
57
|
|
48
|
-
|
58
|
+
See the full list of options for
|
59
|
+
[Ferrum](https://github.com/rubycdp/ferrum#customization).
|
49
60
|
|
50
|
-
You can
|
61
|
+
You can pass options with the following code in your test setup:
|
51
62
|
|
52
63
|
``` ruby
|
53
64
|
Capybara.register_driver(:cuprite) do |app|
|
@@ -55,47 +66,52 @@ Capybara.register_driver(:cuprite) do |app|
|
|
55
66
|
end
|
56
67
|
```
|
57
68
|
|
58
|
-
|
69
|
+
`Cuprite`-specific options are:
|
70
|
+
|
71
|
+
* options `Hash`
|
72
|
+
* `:url_blacklist` (Array) - array of strings to match against requested URLs
|
73
|
+
* `:url_whitelist` (Array) - array of strings to match against requested URLs
|
59
74
|
|
60
|
-
|
75
|
+
|
76
|
+
## Debugging
|
77
|
+
|
78
|
+
If you pass `inspector` option, remote debugging will be enabled if you run
|
79
|
+
tests with `INSPECTOR=true`. Then you can put `page.driver.debug` or
|
80
|
+
`page.driver.debug(binding)` in your test to pause it. This will launch the
|
81
|
+
browser where you can inspect the content.
|
61
82
|
|
62
83
|
```ruby
|
63
|
-
Capybara
|
84
|
+
Capybara.register_driver :cuprite do |app|
|
85
|
+
Capybara::Cuprite::Driver.new(app, inspector: ENV['INSPECTOR'])
|
86
|
+
end
|
64
87
|
```
|
65
88
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
* `:port` (Integer) - Remote debugging port for headless Chrome
|
84
|
-
* `:host` (String) - Remote debugging address for headless Chrome
|
85
|
-
* `:url` (String) - URL for a running instance of Chrome. If this is set, a
|
86
|
-
browser process will not be spawned.
|
87
|
-
* `:url_blacklist` (Array) - array of strings to match against requested URLs
|
88
|
-
* `:url_whitelist` (Array) - array of strings to match against requested URLs
|
89
|
-
* `:process_timeout` (Integer) - How long to wait for the Chrome process to
|
90
|
-
respond on startup
|
89
|
+
then somewhere in the test:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
it "does something useful" do
|
93
|
+
visit root_path
|
94
|
+
|
95
|
+
fill_in "field", with: "value"
|
96
|
+
page.driver.debug(binding)
|
97
|
+
|
98
|
+
expect(page).to have_content("value")
|
99
|
+
end
|
100
|
+
```
|
101
|
+
|
102
|
+
In the middle of the execution Chrome will open a new tab where you can inspect
|
103
|
+
the content and also if you passed `binding` an `irb` or `pry` console will be
|
104
|
+
opened where you can further experiment with the test.
|
105
|
+
|
91
106
|
|
92
|
-
|
107
|
+
## Clicking/Scrolling
|
93
108
|
|
94
109
|
* `page.driver.click(x, y)` Click a very specific area of the screen.
|
95
|
-
* `page.driver.scroll_to(left, top)` Scroll to given position.
|
96
|
-
* `element.send_keys(*keys)` Send keys to given node.
|
110
|
+
* `page.driver.scroll_to(left, top)` Scroll to a given position.
|
111
|
+
* `element.send_keys(*keys)` Send keys to a given node.
|
97
112
|
|
98
|
-
|
113
|
+
|
114
|
+
## Request headers
|
99
115
|
|
100
116
|
Manipulate HTTP request headers like a boss:
|
101
117
|
|
@@ -111,10 +127,11 @@ Notice that `headers=` will overwrite already set headers. You should use
|
|
111
127
|
subsequent HTTP requests (including requests for assets, AJAX, etc). They will
|
112
128
|
be automatically cleared at the end of the test.
|
113
129
|
|
114
|
-
### Network traffic ###
|
115
130
|
|
116
|
-
|
117
|
-
|
131
|
+
## Network traffic
|
132
|
+
|
133
|
+
* `page.driver.network_traffic` Inspect network traffic (loaded resources) on
|
134
|
+
the current page. This returns an array of request objects.
|
118
135
|
|
119
136
|
```ruby
|
120
137
|
page.driver.network_traffic # => [Request, ...]
|
@@ -124,7 +141,8 @@ request.response
|
|
124
141
|
|
125
142
|
* `page.driver.wait_for_network_idle` Natively waits for network idle and if
|
126
143
|
there are no active connections returns or raises `TimeoutError` error. Accepts
|
127
|
-
the same options as
|
144
|
+
the same options as
|
145
|
+
[`wait_for_idle`](https://github.com/rubycdp/ferrum#wait_for_idleoptions)
|
128
146
|
|
129
147
|
```ruby
|
130
148
|
page.driver.wait_for_network_idle
|
@@ -136,7 +154,7 @@ manually clear the network traffic by calling `page.driver.clear_network_traffic
|
|
136
154
|
or `page.driver.reset`
|
137
155
|
|
138
156
|
|
139
|
-
|
157
|
+
## Manipulating cookies
|
140
158
|
|
141
159
|
The following methods are used to inspect and manipulate cookies:
|
142
160
|
|
@@ -151,18 +169,22 @@ The following methods are used to inspect and manipulate cookies:
|
|
151
169
|
* `page.driver.remove_cookie(name)` - remove a cookie
|
152
170
|
* `page.driver.clear_cookies` - clear all cookies
|
153
171
|
|
154
|
-
|
172
|
+
|
173
|
+
## Screenshot
|
155
174
|
|
156
175
|
Besides capybara screenshot method you can get image as Base64:
|
157
176
|
|
158
177
|
* `page.driver.render_base64(format, options)`
|
159
178
|
|
160
|
-
|
179
|
+
|
180
|
+
## Authorization
|
161
181
|
|
162
182
|
* `page.driver.basic_authorize(user, password)`
|
163
183
|
* `page.driver.set_proxy(ip, port, type, user, password)`
|
164
184
|
|
165
|
-
|
185
|
+
|
186
|
+
## URL Blacklisting & Whitelisting
|
187
|
+
|
166
188
|
Cuprite supports URL blacklisting, which allows you to prevent scripts from
|
167
189
|
running on designated domains:
|
168
190
|
|
@@ -170,8 +192,8 @@ running on designated domains:
|
|
170
192
|
page.driver.browser.url_blacklist = ["http://www.example.com"]
|
171
193
|
```
|
172
194
|
|
173
|
-
and also URL whitelisting, which allows scripts to only run
|
174
|
-
|
195
|
+
and also URL whitelisting, which allows scripts to only run on designated
|
196
|
+
domains:
|
175
197
|
|
176
198
|
```ruby
|
177
199
|
page.driver.browser.url_whitelist = ["http://www.example.com"]
|
@@ -181,22 +203,8 @@ If you are experiencing slower run times, consider creating a URL whitelist of
|
|
181
203
|
domains that are essential or a blacklist of domains that are not essential,
|
182
204
|
such as ad networks or analytics, to your testing environment.
|
183
205
|
|
184
|
-
### Remote debugging ###
|
185
|
-
|
186
|
-
If you use the `inspector: true` option, remote debugging will be enabled. When
|
187
|
-
this option is enabled, you can insert `page.driver.debug` into your tests to
|
188
|
-
pause the test and launch a browser which gives you the Chrome inspector to view
|
189
|
-
all your open pages and inspect them.
|
190
|
-
|
191
|
-
You could set the inspector option via an environment variable:
|
192
|
-
|
193
|
-
```ruby
|
194
|
-
Capybara.register_driver :cuprite do |app|
|
195
|
-
Capybara::Cuprite::Driver.new(app, inspector: ENV['INSPECTOR'])
|
196
|
-
end
|
197
|
-
```
|
198
206
|
|
199
|
-
## License
|
207
|
+
## License
|
200
208
|
|
201
209
|
Copyright 2018-2020 Machinio
|
202
210
|
|
@@ -300,13 +300,26 @@ module Capybara::Cuprite
|
|
300
300
|
end
|
301
301
|
alias_method :authorize, :basic_authorize
|
302
302
|
|
303
|
-
def
|
303
|
+
def debug_url
|
304
|
+
"http://#{browser.process.host}:#{browser.process.port}"
|
305
|
+
end
|
306
|
+
|
307
|
+
def debug(binding = nil)
|
304
308
|
if @options[:inspector]
|
305
|
-
Process.spawn(browser.process.path,
|
306
|
-
|
309
|
+
Process.spawn(browser.process.path, debug_url)
|
310
|
+
|
311
|
+
if binding&.respond_to?(:pry)
|
312
|
+
Pry.start(binding)
|
313
|
+
elsif binding&.respond_to?(:irb)
|
314
|
+
binding.irb
|
315
|
+
else
|
316
|
+
pause
|
317
|
+
end
|
307
318
|
else
|
308
319
|
raise Error, "To use the remote debugging, you have to launch " \
|
309
|
-
"the driver with `inspector:
|
320
|
+
"the driver with `inspector: ENV['INSPECTOR']` " \
|
321
|
+
"configuration option and run your test suite passing " \
|
322
|
+
"env variable"
|
310
323
|
end
|
311
324
|
end
|
312
325
|
|
@@ -317,7 +330,7 @@ module Capybara::Cuprite
|
|
317
330
|
# In jRuby - STDIN returns immediately from select
|
318
331
|
# see https://github.com/jruby/jruby/issues/1783
|
319
332
|
read, write = IO.pipe
|
320
|
-
Thread.new { IO.copy_stream(STDIN, write); write.close }
|
333
|
+
thread = Thread.new { IO.copy_stream(STDIN, write); write.close }
|
321
334
|
|
322
335
|
STDERR.puts "Cuprite execution paused. Press enter (or run 'kill -CONT #{Process.pid}') to continue."
|
323
336
|
|
@@ -333,6 +346,8 @@ module Capybara::Cuprite
|
|
333
346
|
end
|
334
347
|
end
|
335
348
|
ensure
|
349
|
+
thread.kill
|
350
|
+
read.close
|
336
351
|
trap("SIGCONT", old_trap) # Restore the previous signal handler, if there was one.
|
337
352
|
STDERR.puts "Continuing"
|
338
353
|
end
|
@@ -144,16 +144,16 @@ module Capybara::Cuprite
|
|
144
144
|
command(:disabled?)
|
145
145
|
end
|
146
146
|
|
147
|
-
def click(keys = [],
|
148
|
-
prepare_and_click(:left, __method__, keys,
|
147
|
+
def click(keys = [], **options)
|
148
|
+
prepare_and_click(:left, __method__, keys, options)
|
149
149
|
end
|
150
150
|
|
151
|
-
def right_click(keys = [],
|
152
|
-
prepare_and_click(:right, __method__, keys,
|
151
|
+
def right_click(keys = [], **options)
|
152
|
+
prepare_and_click(:right, __method__, keys, options)
|
153
153
|
end
|
154
154
|
|
155
|
-
def double_click(keys = [],
|
156
|
-
prepare_and_click(:double, __method__, keys,
|
155
|
+
def double_click(keys = [], **options)
|
156
|
+
prepare_and_click(:double, __method__, keys, options)
|
157
157
|
end
|
158
158
|
|
159
159
|
def hover
|
@@ -225,9 +225,12 @@ module Capybara::Cuprite
|
|
225
225
|
|
226
226
|
private
|
227
227
|
|
228
|
-
def prepare_and_click(mode, name, keys,
|
228
|
+
def prepare_and_click(mode, name, keys, options)
|
229
|
+
delay = options[:delay].to_i
|
230
|
+
x, y = options.values_at(:x, :y)
|
231
|
+
offset = { x: x, y: y, position: options[:offset] || :top }
|
229
232
|
command(:before_click, name, keys, offset)
|
230
|
-
node.click(mode: mode, keys: keys, offset: offset)
|
233
|
+
node.click(mode: mode, keys: keys, offset: offset, delay: delay)
|
231
234
|
end
|
232
235
|
|
233
236
|
def filter_text(text)
|
@@ -94,7 +94,12 @@ module Capybara::Cuprite
|
|
94
94
|
|
95
95
|
def before_click(node, name, keys = [], offset = {})
|
96
96
|
evaluate_on(node: node, expression: "_cuprite.scrollIntoViewport(this)")
|
97
|
-
|
97
|
+
|
98
|
+
# If offset is given it may go outside of the element and likely error
|
99
|
+
# will be raised that we detected another element at this position.
|
100
|
+
return true if offset[:x] || offset[:y]
|
101
|
+
|
102
|
+
x, y = find_position(node, **offset)
|
98
103
|
evaluate_on(node: node, expression: "_cuprite.mouseEventTest(this, '#{name}', #{x}, #{y})")
|
99
104
|
true
|
100
105
|
rescue Ferrum::JavaScriptError => e
|
@@ -174,8 +179,8 @@ module Capybara::Cuprite
|
|
174
179
|
end
|
175
180
|
end
|
176
181
|
|
177
|
-
def find_position(node,
|
178
|
-
x, y = node.find_position(
|
182
|
+
def find_position(node, **options)
|
183
|
+
x, y = node.find_position(**options)
|
179
184
|
rescue Ferrum::BrowserError => e
|
180
185
|
if e.message == "Could not compute content quads."
|
181
186
|
raise MouseEventFailed.new("MouseEventFailed: click, none, 0, 0")
|
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.10'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Vorotilin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -36,14 +36,14 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 0.
|
39
|
+
version: 0.8.0
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 0.
|
46
|
+
version: 0.8.0
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: image_size
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -208,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
208
208
|
- !ruby/object:Gem::Version
|
209
209
|
version: '0'
|
210
210
|
requirements: []
|
211
|
-
rubygems_version: 3.
|
211
|
+
rubygems_version: 3.1.2
|
212
212
|
signing_key:
|
213
213
|
specification_version: 4
|
214
214
|
summary: Headless Chrome driver for Capybara
|