Skip to content

Commit

Permalink
Merge pull request #1549 from artsy/jonallured/chore-upgrade-and-simp…
Browse files Browse the repository at this point in the history
…lify-browser-testing-setup

chore: Upgrade and simplify browser testing setup
  • Loading branch information
jonallured authored Dec 5, 2024
2 parents c8c4ad0 + bbf2f03 commit 13a574b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 46 deletions.
1 change: 0 additions & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
--color
--order random
--format documentation
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ RUN apk update && apk --no-cache --quiet add \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& adduser -D -g '' deploy

ENV CHROMEDRIVER_PATH=/usr/bin/chromedriver

RUN gem install bundler && \
bundle config --global frozen 1

Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ group :development, :test do
gem "pry-byebug"
gem "rspec-rails"
gem "standard"
gem "webdrivers"
end

group :development do
Expand Down
36 changes: 19 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ GEM
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
amq-protocol (2.3.2)
artsy-auth (0.2.0)
omniauth-artsy (>= 0.4.0)
Expand Down Expand Up @@ -97,6 +97,7 @@ GEM
aws-sigv4 (1.8.0)
aws-eventstream (~> 1, >= 1.0.2)
backport (1.2.0)
base64 (0.2.0)
benchmark (0.4.0)
bigdecimal (3.1.8)
bootsnap (1.18.4)
Expand All @@ -114,15 +115,15 @@ GEM
bunny (2.17.0)
amq-protocol (~> 2.3, >= 2.3.1)
byebug (11.1.3)
capybara (3.35.3)
capybara (3.40.0)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
nokogiri (~> 1.11)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
childprocess (3.0.0)
coderay (1.1.3)
coffee-rails (5.0.0)
coffee-script (>= 2.2.0)
Expand Down Expand Up @@ -272,6 +273,7 @@ GEM
listen (3.4.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
logger (1.6.2)
loofah (2.23.1)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand All @@ -282,6 +284,7 @@ GEM
net-pop
net-smtp
marcel (1.0.2)
matrix (0.4.2)
method_source (1.0.0)
mini_mime (1.1.5)
mini_portile2 (2.8.8)
Expand Down Expand Up @@ -352,11 +355,11 @@ GEM
pry-byebug (3.9.0)
byebug (~> 11.0)
pry (~> 0.13.0)
public_suffix (4.0.6)
public_suffix (6.0.1)
puma (5.6.9)
nio4r (~> 2.0)
racc (1.8.1)
rack (2.2.8.1)
rack (2.2.10)
rack-cors (1.1.1)
rack (>= 2.0.0)
rack-livereload (0.3.17)
Expand Down Expand Up @@ -409,7 +412,7 @@ GEM
ffi (~> 1.0)
redcarpet (3.5.1)
redis (4.8.1)
regexp_parser (2.9.2)
regexp_parser (2.9.3)
restforce (5.3.0)
faraday (>= 0.9.0, <= 1.10.0)
faraday_middleware (>= 0.8.8, <= 2.0)
Expand Down Expand Up @@ -458,7 +461,7 @@ GEM
ruby2_keywords (0.0.5)
ruby_parser (3.15.1)
sexp_processor (~> 4.9)
rubyzip (2.3.0)
rubyzip (2.3.2)
sass (3.7.4)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
Expand All @@ -474,9 +477,12 @@ GEM
sprockets (> 3.0)
sprockets-rails
tilt
selenium-webdriver (3.142.7)
childprocess (>= 0.5, < 4.0)
rubyzip (>= 1.2.2)
selenium-webdriver (4.26.0)
base64 (~> 0.2)
logger (~> 1.4)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
sentry-rails (5.21.0)
railties (>= 5.0)
sentry-ruby (~> 5.21.0)
Expand Down Expand Up @@ -540,14 +546,11 @@ GEM
uniform_notifier (1.16.0)
unleash (4.0.0)
murmurhash3 (~> 0.1.6)
webdrivers (4.6.0)
nokogiri (~> 1.6)
rubyzip (>= 1.3.0)
selenium-webdriver (>= 3.0, < 4.0)
webmock (3.12.2)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
websocket (1.2.11)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand Down Expand Up @@ -618,7 +621,6 @@ DEPENDENCIES
uglifier
unleash
watt!
webdrivers
webmock
yarjuf

Expand Down
1 change: 0 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ if Rails.env.development? || Rails.env.test?
abort "schema-check failed" unless $CHILD_STATUS.exitstatus.zero?
end

require "standard/rake"
Rake::Task[:default].clear
task default: %i[schema_check standard spec]
end
33 changes: 9 additions & 24 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
require "rack_session_access/capybara"

WebMock.disable_net_connect!(
allow_localhost: true,
allow: "chromedriver.storage.googleapis.com"
allow_localhost: true
)

ActiveRecord::Migration.maintain_test_schema!
Expand Down Expand Up @@ -53,39 +52,25 @@
end
end

Capybara.server = :puma, {Silent: true}
Capybara.configure do |config|
config.javascript_driver =
ENV["NO_HEADLESS"] ? :selenium_chrome : :headless_chrome
config.javascript_driver = :headless_chrome
config.default_max_wait_time = 10
config.ignore_hidden_elements = false
end

def prepare_chromedriver(selenium_driver_args)
if (driver_path = ENV["CHROMEDRIVER_PATH"])
service = Selenium::WebDriver::Service.new(path: driver_path, port: 9_005)
selenium_driver_args[:service] = service
else
require "webdrivers/chromedriver"
end
end

Capybara.register_driver :headless_chrome do |app|
caps =
Selenium::WebDriver::Remote::Capabilities.chrome(
loggingPrefs: {
browser: "ALL"
}
)
opts = Selenium::WebDriver::Chrome::Options.new(options: {"w3c" => false})
opts = Selenium::WebDriver::Chrome::Options.new

opts.add_argument("--headless")
opts.add_argument("--no-sandbox")
opts.add_argument("--disable-dev-shm-usage")
opts.add_argument("--window-size=1440,900")
opts.add_preference(:loggingPrefs, {browser: "ALL"})

args = {browser: :chrome, options: opts, desired_capabilities: caps}

prepare_chromedriver(args)
args = {
browser: :chrome,
options: opts
}

Capybara::Selenium::Driver.new(app, **args)
end

0 comments on commit 13a574b

Please sign in to comment.