Skip to content

Commit f4f0a6b

Browse files
Migrate capybara driver to cuprite
1 parent 7dc0a7b commit f4f0a6b

File tree

8 files changed

+75
-31
lines changed

8 files changed

+75
-31
lines changed

.github/workflows/ci.yml

+1-8
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@ jobs:
3333
--health-retries 5
3434
steps:
3535
- uses: actions/checkout@v2
36-
- uses: nanasess/[email protected]
37-
with:
38-
chromedriver-version: '117.0.5938.92'
39-
- run: |
40-
export DISPLAY=:99
41-
chromedriver --url-base=/wd/hub &
42-
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 &
4336
- name: Set up Ruby
4437
uses: ruby/setup-ruby@v1
4538
with:
@@ -52,6 +45,6 @@ jobs:
5245
- name: Run tests
5346
run: bundle exec rake
5447
env:
55-
CAPYBARA_DRIVER: selenium_chrome_headless
48+
CAPYBARA_DRIVER: better_cuprite
5649
COMPILE_ASSETS: 0
5750
EAGER_LOAD: 1

Gemfile

-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ group :development, :test do
7373
gem 'dotenv-rails'
7474

7575
gem 'site_prism'
76-
gem 'selenium-webdriver'
77-
7876
gem 'factory_bot_rails'
7977

8078
gem 'ruby_spec_helpers', path: 'vendor/gems/ruby_spec_helpers'

Gemfile.lock

+25-15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ PATH
33
specs:
44
ruby_spec_helpers (0.0.1)
55
capybara
6+
cuprite
67
rspec-collection_matchers
78
rspec-rails
89
rspec-retry (~> 0.4.5)
@@ -134,6 +135,9 @@ GEM
134135
crass (1.0.6)
135136
cssbundling-rails (1.1.2)
136137
railties (>= 6.0.0)
138+
cuprite (0.15)
139+
capybara (~> 3.0)
140+
ferrum (~> 0.14.0)
137141
date (3.3.3)
138142
db-query-matchers (0.11.0)
139143
activesupport (>= 4.0, < 7.1)
@@ -174,6 +178,11 @@ GEM
174178
multipart-post (>= 1.2, < 3)
175179
faraday_middleware (0.14.0)
176180
faraday (>= 0.7.4, < 1.0)
181+
ferrum (0.14)
182+
addressable (~> 2.5)
183+
concurrent-ruby (~> 1.1)
184+
webrick (~> 1.7)
185+
websocket-driver (>= 0.6, < 0.8)
177186
ffi (1.15.5)
178187
foreman (0.87.2)
179188
gh (0.14.0)
@@ -225,7 +234,7 @@ GEM
225234
listen (3.8.0)
226235
rb-fsevent (~> 0.10, >= 0.10.3)
227236
rb-inotify (~> 0.9, >= 0.9.10)
228-
loofah (2.21.3)
237+
loofah (2.21.4)
229238
crass (~> 1.0.2)
230239
nokogiri (>= 1.12.0)
231240
mail (2.7.1)
@@ -237,10 +246,10 @@ GEM
237246
mime-types-data (~> 3.2015)
238247
mime-types-data (3.2023.0218.1)
239248
mini_mime (1.1.2)
240-
mini_portile2 (2.8.2)
249+
mini_portile2 (2.8.5)
241250
mini_racer (0.6.3)
242251
libv8-node (~> 16.10.0.0)
243-
minitest (5.18.1)
252+
minitest (5.20.0)
244253
msgpack (1.6.1)
245254
multi_json (1.15.0)
246255
multipart-post (2.3.0)
@@ -257,16 +266,16 @@ GEM
257266
net-smtp (0.3.3)
258267
net-protocol
259268
nio4r (2.5.9)
260-
nokogiri (1.15.2)
269+
nokogiri (1.15.4)
261270
mini_portile2 (~> 2.8.2)
262271
racc (~> 1.4)
263-
nokogiri (1.15.2-arm64-darwin)
272+
nokogiri (1.15.4-arm64-darwin)
264273
racc (~> 1.4)
265-
nokogiri (1.15.2-x86_64-darwin)
274+
nokogiri (1.15.4-x86_64-darwin)
266275
racc (~> 1.4)
267-
nokogiri (1.15.2-x86_64-linux)
276+
nokogiri (1.15.4-x86_64-linux)
268277
racc (~> 1.4)
269-
octicons (17.12.0)
278+
octicons (19.8.0)
270279
omniauth (2.1.1)
271280
hashie (>= 3.4.6)
272281
rack (>= 2.2.3)
@@ -282,10 +291,10 @@ GEM
282291
parser (3.2.1.0)
283292
ast (~> 2.4.1)
284293
pg (1.4.5)
285-
primer_view_components (0.1.0)
294+
primer_view_components (0.1.9)
286295
actionview (>= 5.0.0)
287296
activesupport (>= 5.0.0)
288-
octicons (>= 17.0.0)
297+
octicons (>= 18.0.0)
289298
view_component (> 2.0, < 4.0)
290299
pry (0.14.2)
291300
coderay (~> 1.1)
@@ -302,7 +311,7 @@ GEM
302311
pusher-client (0.6.2)
303312
json
304313
websocket (~> 1.0)
305-
racc (1.7.1)
314+
racc (1.7.3)
306315
rack (2.2.7)
307316
rack-protection (3.0.5)
308317
rack
@@ -323,8 +332,9 @@ GEM
323332
activesupport (= 7.0.6)
324333
bundler (>= 1.15.0)
325334
railties (= 7.0.6)
326-
rails-dom-testing (2.0.3)
327-
activesupport (>= 4.2.0)
335+
rails-dom-testing (2.2.0)
336+
activesupport (>= 5.0.0)
337+
minitest
328338
nokogiri (>= 1.6)
329339
rails-html-sanitizer (1.6.0)
330340
loofah (~> 2.21)
@@ -464,7 +474,7 @@ GEM
464474
tzinfo (2.0.6)
465475
concurrent-ruby (~> 1.0)
466476
unicode-display_width (2.4.2)
467-
view_component (2.82.0)
477+
view_component (3.7.0)
468478
activesupport (>= 5.2.0, < 8.0)
469479
concurrent-ruby (~> 1.0)
470480
method_source (~> 1.0)
@@ -479,6 +489,7 @@ GEM
479489
addressable (>= 2.8.0)
480490
crack (>= 0.3.2)
481491
hashdiff (>= 0.4.0, < 2.0.0)
492+
webrick (1.8.1)
482493
websocket (1.2.10)
483494
websocket-driver (0.7.5)
484495
websocket-extensions (>= 0.1.0)
@@ -543,7 +554,6 @@ DEPENDENCIES
543554
responders
544555
rspec-rails
545556
ruby_spec_helpers!
546-
selenium-webdriver
547557
sentry-raven
548558
shoulda-matchers
549559
simple_form

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ export WHITELIST_CORS_HOSTS=yoursite.example.org,othersite.example.org
6767
#### Configuration for Chrome extension
6868
In order to use the TestTrack Chrome extension, you will need to set up the `BROWSER_EXTENSION_SHARED_SECRET` environment variable. [Details.](https://github.com/Betterment/test_track_chrome_extension#building-the-extension)
6969

70+
#### Running specs
71+
72+
To run all specs:
73+
```bash
74+
bundle exec rspec
75+
```
76+
77+
If you are interested in hitting a `binding.pry` somewhere while playing around with your development environment, you can use `binding.pry_remote` in your code. When reloading the page you expect to have the breakpoint, the browser should freeze and you should be able to connect to your console via running in your terminal `pry-remote`. Pry away as normal!
78+
79+
If you are curious to see your integration tests running in a non-headless manner, run your test this way:
80+
81+
```
82+
$ CAPYBARA_DEBUG=1 bundle exec rspec <path to file>/<file>s
83+
```
84+
7085
## Managing your installation
7186
There are a few things that you will need to do in the TestTrack application:
7287
* Create `App`s -- client applications that will manage splits on your TestTrack server

spec/rails_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ENV['RAILS_ENV'] ||= 'test'
2-
ENV['CAPYBARA_DRIVER'] ||= ENV['CI'] ? 'selenium_remote_chrome' : 'selenium_chrome_headless'
2+
ENV['CAPYBARA_DRIVER'] ||= 'better_cuprite'
33
ENV['DATADOG_ENABLED'] = '1'
44

55
require File.expand_path('../config/environment', __dir__)

spec/system/admin_split_decision_create_spec.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@
3030
split_page.decide_split.click
3131
expect(split_decision_page).to be_loaded
3232

33-
split_decision_page.create_form.tap do |form|
34-
form.variant_options.select 'touch_this'
35-
form.submit_button.click
36-
accept_alert(/You are deciding/)
33+
accept_alert(/You are deciding/) do
34+
split_decision_page.create_form.tap do |form|
35+
form.variant_options.select 'touch_this'
36+
form.submit_button.click
37+
end
3738
end
3839

3940
expect(split_page).to be_loaded

vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/capybara_configuration.rb

+26
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
11
require 'capybara/rails'
22
require 'capybara/rspec'
33
require 'selenium-webdriver'
4+
require 'capybara/cuprite'
45
require 'fileutils'
56

67
driver = ENV.fetch("CAPYBARA_DRIVER", "selenium_chrome_headless").to_sym
78

89
case driver
10+
when :better_cuprite
11+
# NOTE: The name :cuprite is already registered by Rails,
12+
# See https://github.com/rubycdp/cuprite/issues/180
13+
Capybara.register_driver(:better_cuprite) do |app|
14+
browser_options = {
15+
'disable-smooth-scrolling': true,
16+
}.tap do |opts|
17+
opts['no-sandbox'] = nil if ENV['CI']
18+
end
19+
20+
options = {
21+
window_size: [1280, 1024],
22+
timeout: ENV.fetch('CUPRITE_TIMEOUT', 15),
23+
process_timeout: ENV.fetch('CUPRITE_TIMEOUT', 15),
24+
js_errors: false,
25+
browser_options: browser_options,
26+
}
27+
28+
if ENV['CAPYBARA_DEBUG']
29+
options[:headless] = false
30+
options[:slowmo] = 0.1
31+
end
32+
33+
Capybara::Cuprite::Driver.new(app, **options)
34+
end
935
when :webkit
1036
Capybara.register_driver :webkit do |app|
1137
browser = Capybara::Webkit::Browser.new(Capybara::Webkit::Connection.new).tap do |browser|

vendor/gems/ruby_spec_helpers/ruby_spec_helpers.gemspec

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ Gem::Specification.new do |s|
1515
s.files = Dir["lib/**/*", "README.md"]
1616

1717
s.add_dependency 'capybara'
18+
s.add_dependency 'cuprite'
19+
s.add_dependency 'rspec_junit_formatter'
1820
s.add_dependency 'rspec-collection_matchers'
1921
s.add_dependency 'rspec-rails'
2022
s.add_dependency 'rspec-retry', '~> 0.4.5'
21-
s.add_dependency 'rspec_junit_formatter'
2223
s.add_dependency 'selenium-webdriver'
2324
s.add_dependency 'site_prism'
2425
s.add_dependency 'webmock'

0 commit comments

Comments
 (0)