Skip to content

Commit 93cf7cf

Browse files
authored
Adds a configurable Cuprite driver (#327)
1 parent 131bc0a commit 93cf7cf

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Capybara.javascript_driver = :selenium_billy # Uses Firefox
6565
# Capybara.javascript_driver = :apparition_billy
6666
# Capybara.javascript_driver = :webkit_billy
6767
# Capybara.javascript_driver = :poltergeist_billy
68+
# Capybara.javascript_driver = :cuprite_billy
6869
```
6970

7071
> __Note__: `:poltergeist_billy` doesn't support proxying any localhosts, so you must use
@@ -154,6 +155,20 @@ And /^a stub for google$/ do
154155
end
155156
```
156157

158+
### Setup remote Chrome
159+
160+
In the case you are using a Chrome instance, running on another machine, or in
161+
another Docker container, you need to :
162+
* Fix the Billy proxy host and port
163+
* Passes the `--proxy-server=<billy host>:<billy port>`
164+
165+
#### WebSockets
166+
167+
Puffing billy doesn't support websockets, so if you are using them,
168+
or ActionCable for the Ruby On Rails developers, you can tell Chrome to bypass
169+
the proxy for websockets by adding the flag `--proxy-bypass-list=ws://*` to
170+
your remote chrome intance or Docker container.
171+
157172
## Minitest Usage
158173

159174
Please see [this link](https://gist.github.com/sauy7/1b081266dd453a1b737b) for

lib/billy/browsers/capybara.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ class Capybara
88
poltergeist: 'capybara/poltergeist',
99
webkit: 'capybara/webkit',
1010
selenium: 'selenium/webdriver',
11-
apparition: 'capybara/apparition'
11+
apparition: 'capybara/apparition',
12+
cuprite: 'capybara/cuprite'
1213
}
1314

1415
def self.register_drivers
@@ -108,6 +109,20 @@ def self.register_apparition_driver
108109
end
109110
end
110111

112+
def self.register_cuprite_driver
113+
driver_otions = {
114+
browser_options: {
115+
'ignore-certificate-errors' => nil
116+
}
117+
}.deep_merge(Billy.config.cuprite_options)
118+
119+
::Capybara.register_driver :cuprite_billy do |app|
120+
::Capybara::Cuprite::Driver.new(app, **driver_otions).tap do |driver|
121+
driver.set_proxy(Billy.proxy.host, Billy.proxy.port)
122+
end
123+
end
124+
end
125+
111126
def self.build_selenium_options_for_firefox
112127
profile = Selenium::WebDriver::Firefox::Profile.new.tap do |prof|
113128
prof.proxy = Selenium::WebDriver::Proxy.new(

lib/billy/config.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class Config
1111
:non_whitelisted_requests_disabled, :cache_path, :certs_path, :verify_peer, :proxy_host, :proxy_port, :proxied_request_inactivity_timeout,
1212
:proxied_request_connect_timeout, :dynamic_jsonp, :dynamic_jsonp_keys, :dynamic_jsonp_callback_name, :merge_cached_responses_whitelist,
1313
:strip_query_params, :proxied_request_host, :proxied_request_port, :cache_request_body_methods, :after_cache_handles_request,
14-
:cache_simulates_network_delays, :cache_simulates_network_delay_time, :record_requests, :record_stub_requests, :use_ignore_params, :before_handle_request
14+
:cache_simulates_network_delays, :cache_simulates_network_delay_time, :record_requests, :record_stub_requests, :use_ignore_params,
15+
:before_handle_request, :cuprite_options
1516

1617
def initialize
1718
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
@@ -53,6 +54,7 @@ def reset
5354
@record_stub_requests = false
5455
@use_ignore_params = true
5556
@before_handle_request = nil
57+
@cuprite_options = {}
5658
end
5759
end
5860

0 commit comments

Comments
 (0)