Skip to content

Commit e2b678f

Browse files
committed
Update README [ci skip]
1 parent 2782952 commit e2b678f

File tree

1 file changed

+58
-76
lines changed

1 file changed

+58
-76
lines changed

README.md

Lines changed: 58 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,31 @@
22

33
[![Build Status](https://travis-ci.org/rubycdp/cuprite.svg?branch=master)](https://travis-ci.org/rubycdp/cuprite)
44

5-
Cuprite is a pure Ruby driver (read as _no_ Java/Selenium/WebDriver/ChromeDriver
6-
requirement) for [Capybara](https://github.com/teamcapybara/capybara). It allows
7-
you to run your Capybara tests on a headless [Chrome](https://www.google.com/chrome/)
8-
or [Chromium](https://www.chromium.org/) by [CDP protocol](https://chromedevtools.github.io/devtools-protocol/).
9-
Under the hood it uses [Ferrum](https://github.com/route/ferrum) which is
10-
high-level API to the browser again by CDP protocol.
11-
12-
The emphasis was made on raw CDP protocol because Headless Chrome allows you to
13-
do so many things that are barely supported by WebDriver because it should have
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.
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.
12+
13+
Since Cuprite uses [Ferrum](https://github.com/rubycdp/ferrum#examples) there
14+
are many useful methods you can call even using this driver:
15+
16+
```ruby
17+
browser = page.driver.browser
18+
browser.mouse.move(x: 123, y: 456).down.up
19+
```
20+
1721

1822
## Install
1923

20-
Add these lines to your `Gemfile` and run `bundle install`.
24+
Add this to your `Gemfile` and run `bundle install`.
2125

2226
``` ruby
23-
gem "cuprite", group: :test
27+
group :test do
28+
gem "cuprite"
29+
end
2430
```
2531

2632
In your test setup add:
@@ -33,77 +39,51 @@ Capybara.register_driver(:cuprite) do |app|
3339
end
3440
```
3541

36-
If you already had tests on Poltergeist then it should simply work, for Selenium
37-
you better check your code for `.manage` calls because things are much easier
38-
with Cuprite, see the documentation below.
42+
if you use `Docker` don't forget to pass `no-sandbox` option:
43+
44+
```ruby
45+
Capybara::Cuprite::Driver.new(app, browser_options: { 'no-sandbox': nil })
46+
```
3947

40-
## Install Chrome
48+
If you already have tests on Poltergeist then it should simply work, for
49+
Selenium you better check your code for `manage` calls because it works
50+
differently in Cuprite, see the documentation below.
4151

42-
There's no official Chrome or Chromium package for Linux don't install it this
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
4752

4853
## Customization
4954

50-
You can customize options with the following code in your test setup:
55+
See the full list of options for
56+
[Ferrum](https://github.com/rubycdp/ferrum#customization).
57+
58+
You can pass options with the following code in your test setup:
5159

5260
``` ruby
5361
Capybara.register_driver(:cuprite) do |app|
5462
Capybara::Cuprite::Driver.new(app, options)
5563
end
5664
```
5765

58-
#### Running in Docker
59-
60-
In docker as root you must pass the no-sandbox browser option:
61-
62-
```ruby
63-
Capybara::Cuprite::Driver.new(app, browser_options: { 'no-sandbox': nil })
64-
```
66+
`Cuprite`-specific options are:
6567

6668
* options `Hash`
67-
* `:browser_path` (String) - Path to chrome binary, you can also set ENV
68-
variable as `BROWSER_PATH=some/path/chrome bundle exec rspec`.
69-
* `:headless` (Boolean) - Set browser as headless or not, `true` by default.
70-
* `:slowmo` (Integer | Float) - Set a delay to wait before sending command.
71-
Usefull companion of headless option, so that you have time to see changes.
72-
* `:logger` (Object responding to `puts`) - When present, debug output is
73-
written to this object.
74-
* `:timeout` (Numeric) - The number of seconds we'll wait for a response when
75-
communicating with browser. Default is 5.
76-
* `:js_errors` (Boolean) - When true, JavaScript errors get re-raised in Ruby.
77-
* `:window_size` (Array) - The dimensions of the browser window in which to
78-
test, expressed as a 2-element array, e.g. [1024, 768]. Default: [1024, 768]
79-
* `:browser_options` (Hash) - Additional command line options,
80-
[see them all](https://peter.sh/experiments/chromium-command-line-switches/)
81-
e.g. `{ "ignore-certificate-errors" => nil }`
82-
* `:extensions` (Array) - An array of JS files to be preloaded into the browser
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.
8769
* `:url_blacklist` (Array) - array of strings to match against requested URLs
8870
* `: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
9171

92-
### Remote debugging
9372

94-
If you pass `inspector: ENV['INSPECTOR']` option, remote debugging will be
95-
enabled. When this option is enabled, you can insert `page.driver.debug` or
96-
`page.driver.debug(binding)` into your tests to pause the test and launch a
97-
browser which gives you the Chrome inspector to view all of your open pages and
98-
inspect them.
73+
## Debugging
74+
75+
If you pass `inspector` option, remote debugging will be enabled if you run
76+
tests with `INSPECTOR=true`. Then you can put `page.driver.debug` or
77+
`page.driver.debug(binding)` in your test to pause it. This will launch the
78+
browser where you can inspect the content.
9979

10080
```ruby
10181
Capybara.register_driver :cuprite do |app|
10282
Capybara::Cuprite::Driver.new(app, inspector: ENV['INSPECTOR'])
10383
end
10484
```
10585

106-
then somewhere deep in the test:
86+
then somewhere in the test:
10787

10888
```ruby
10989
it "does something useful" do
@@ -117,16 +97,16 @@ end
11797
```
11898

11999
In the middle of the execution Chrome will open a new tab where you can inspect
120-
page's content and also if you passed binding an `irb` or `pry` console will be
121-
opened where you can further test some expressions.
100+
the content and also if you passed `binding` an `irb` or `pry` console will be
101+
opened where you can further experiment with the test.
122102

123-
### Clicking/Scrolling
103+
## Clicking/Scrolling
124104

125105
* `page.driver.click(x, y)` Click a very specific area of the screen.
126-
* `page.driver.scroll_to(left, top)` Scroll to given position.
127-
* `element.send_keys(*keys)` Send keys to given node.
106+
* `page.driver.scroll_to(left, top)` Scroll to a given position.
107+
* `element.send_keys(*keys)` Send keys to a given node.
128108

129-
### Request headers
109+
## Request headers
130110

131111
Manipulate HTTP request headers like a boss:
132112

@@ -142,10 +122,10 @@ Notice that `headers=` will overwrite already set headers. You should use
142122
subsequent HTTP requests (including requests for assets, AJAX, etc). They will
143123
be automatically cleared at the end of the test.
144124

145-
### Network traffic
125+
## Network traffic
146126

147-
* `page.driver.network_traffic` Inspect network traffic (resources have been
148-
loaded) on the current page. This returns an array of request objects.
127+
* `page.driver.network_traffic` Inspect network traffic (loaded resources) on
128+
the current page. This returns an array of request objects.
149129

150130
```ruby
151131
page.driver.network_traffic # => [Request, ...]
@@ -155,7 +135,8 @@ request.response
155135

156136
* `page.driver.wait_for_network_idle` Natively waits for network idle and if
157137
there are no active connections returns or raises `TimeoutError` error. Accepts
158-
the same options as Ferrum's [`wait_for_idle`](https://github.com/route/ferrum#wait_for_idleoptions)
138+
the same options as
139+
[`wait_for_idle`](https://github.com/rubycdp/ferrum#wait_for_idleoptions)
159140

160141
```ruby
161142
page.driver.wait_for_network_idle
@@ -167,7 +148,7 @@ manually clear the network traffic by calling `page.driver.clear_network_traffic
167148
or `page.driver.reset`
168149

169150

170-
### Manipulating cookies
151+
## Manipulating cookies
171152

172153
The following methods are used to inspect and manipulate cookies:
173154

@@ -182,27 +163,28 @@ The following methods are used to inspect and manipulate cookies:
182163
* `page.driver.remove_cookie(name)` - remove a cookie
183164
* `page.driver.clear_cookies` - clear all cookies
184165

185-
### Screenshot
166+
## Screenshot
186167

187168
Besides capybara screenshot method you can get image as Base64:
188169

189170
* `page.driver.render_base64(format, options)`
190171

191-
### Authorization
172+
## Authorization
192173

193174
* `page.driver.basic_authorize(user, password)`
194175
* `page.driver.set_proxy(ip, port, type, user, password)`
195176

196-
### URL Blacklisting & Whitelisting
177+
## URL Blacklisting & Whitelisting
178+
197179
Cuprite supports URL blacklisting, which allows you to prevent scripts from
198180
running on designated domains:
199181

200182
```ruby
201183
page.driver.browser.url_blacklist = ["http://www.example.com"]
202184
```
203185

204-
and also URL whitelisting, which allows scripts to only run
205-
on designated domains:
186+
and also URL whitelisting, which allows scripts to only run on designated
187+
domains:
206188

207189
```ruby
208190
page.driver.browser.url_whitelist = ["http://www.example.com"]

0 commit comments

Comments
 (0)