1
- # Cuprite - Headless Chrome driver for Capybara #
1
+ # Cuprite - Headless Chrome driver for Capybara
2
2
3
3
[ ![ Build Status] ( https://travis-ci.org/machinio/cuprite.svg?branch=master )] ( https://travis-ci.org/machinio/cuprite )
4
4
@@ -15,7 +15,7 @@ consistent design with other browsers. The design of the driver will be as
15
15
close to [ Poltergeist] ( https://github.com/teampoltergeist/poltergeist ) as
16
16
possible though it's not a goal.
17
17
18
- ## Install ##
18
+ ## Install
19
19
20
20
Add these lines to your ` Gemfile ` and run ` bundle install ` .
21
21
@@ -37,15 +37,15 @@ If you already had tests on Poltergeist then it should simply work, for Selenium
37
37
you better check your code for ` .manage ` calls because things are much easier
38
38
with Cuprite, see the documentation below.
39
39
40
- ## Install Chrome ##
40
+ ## Install Chrome
41
41
42
42
There's no official Chrome or Chromium package for Linux don't install it this
43
43
way because it either will be outdated or unofficial, both are bad. Download it
44
44
from official [ source] ( https://www.chromium.org/getting-involved/download-chromium ) .
45
45
Chrome binary should be in the ` PATH ` or ` BROWSER_PATH ` or you can pass it as an
46
46
option
47
47
48
- ## Customization ##
48
+ ## Customization
49
49
50
50
You can customize options with the following code in your test setup:
51
51
@@ -55,7 +55,7 @@ Capybara.register_driver(:cuprite) do |app|
55
55
end
56
56
```
57
57
58
- #### Running in Docker ####
58
+ #### Running in Docker
59
59
60
60
In docker as root you must pass the no-sandbox browser option:
61
61
@@ -89,13 +89,44 @@ Capybara::Cuprite::Driver.new(app, browser_options: { 'no-sandbox': nil })
89
89
* ` :process_timeout ` (Integer) - How long to wait for the Chrome process to
90
90
respond on startup
91
91
92
- ### Clicking/Scrolling ###
92
+ ### Remote debugging
93
+
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.
99
+
100
+ ``` ruby
101
+ Capybara .register_driver :cuprite do |app |
102
+ Capybara ::Cuprite ::Driver .new (app, inspector: ENV [' INSPECTOR' ])
103
+ end
104
+ ```
105
+
106
+ then somewhere deep in the test:
107
+
108
+ ``` ruby
109
+ it " does something useful" do
110
+ visit root_path
111
+
112
+ fill_in " field" , with: " value"
113
+ page.driver.debug(binding )
114
+
115
+ expect(page).to have_content(" value" )
116
+ end
117
+ ```
118
+
119
+ 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.
122
+
123
+ ### Clicking/Scrolling
93
124
94
125
* ` page.driver.click(x, y) ` Click a very specific area of the screen.
95
126
* ` page.driver.scroll_to(left, top) ` Scroll to given position.
96
127
* ` element.send_keys(*keys) ` Send keys to given node.
97
128
98
- ### Request headers ###
129
+ ### Request headers
99
130
100
131
Manipulate HTTP request headers like a boss:
101
132
@@ -111,7 +142,7 @@ Notice that `headers=` will overwrite already set headers. You should use
111
142
subsequent HTTP requests (including requests for assets, AJAX, etc). They will
112
143
be automatically cleared at the end of the test.
113
144
114
- ### Network traffic ###
145
+ ### Network traffic
115
146
116
147
* ` page.driver.network_traffic ` Inspect network traffic (resources have been
117
148
loaded) on the current page. This returns an array of request objects.
@@ -136,7 +167,7 @@ manually clear the network traffic by calling `page.driver.clear_network_traffic
136
167
or ` page.driver.reset `
137
168
138
169
139
- ### Manipulating cookies ###
170
+ ### Manipulating cookies
140
171
141
172
The following methods are used to inspect and manipulate cookies:
142
173
@@ -151,18 +182,18 @@ The following methods are used to inspect and manipulate cookies:
151
182
* ` page.driver.remove_cookie(name) ` - remove a cookie
152
183
* ` page.driver.clear_cookies ` - clear all cookies
153
184
154
- ### Screenshot ###
185
+ ### Screenshot
155
186
156
187
Besides capybara screenshot method you can get image as Base64:
157
188
158
189
* ` page.driver.render_base64(format, options) `
159
190
160
- ### Authorization ###
191
+ ### Authorization
161
192
162
193
* ` page.driver.basic_authorize(user, password) `
163
194
* ` page.driver.set_proxy(ip, port, type, user, password) `
164
195
165
- ### URL Blacklisting & Whitelisting ###
196
+ ### URL Blacklisting & Whitelisting
166
197
Cuprite supports URL blacklisting, which allows you to prevent scripts from
167
198
running on designated domains:
168
199
@@ -181,22 +212,7 @@ If you are experiencing slower run times, consider creating a URL whitelist of
181
212
domains that are essential or a blacklist of domains that are not essential,
182
213
such as ad networks or analytics, to your testing environment.
183
214
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
-
199
- ## License ##
215
+ ## License
200
216
201
217
Copyright 2018-2020 Machinio
202
218
0 commit comments