Skip to content

Commit

Permalink
Revert Docker hacks for system tests
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Jun 17, 2020
1 parent e3d9651 commit b5cace4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 42 deletions.
9 changes: 0 additions & 9 deletions spec/system/support/better_rails_system_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ def absolute_image_path
Rails.root.join("#{Capybara.save_path}/screenshots/#{image_name}.png")
end

# Use relative path in screenshot message to make it clickable in VS Code when running in Docker
def image_path
absolute_image_path.relative_path_from(Rails.root).to_s
end

# Make failure screenshots compatible with multi-session setup
def take_screenshot
return super unless Capybara.last_used_session
Expand All @@ -32,10 +27,6 @@ def take_screenshot

# Make sure this hook runs before others
config.prepend_before(:each, type: :system) do
# Rails sets host to `127.0.0.1` for every test by default.
# That would break in Docker
# NOTE: Fixed in 6.1 (https://github.com/rails/rails/commit/d415eb4f6d6bb24b78b968ae28c22bb7e1721285#diff-9de6fe0bff4847b77cba72441ee855c2)
host! "http://#{Capybara.server_host}"
# Use JS driver always
driven_by Capybara.javascript_driver
end
Expand Down
5 changes: 0 additions & 5 deletions spec/system/support/capybara_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

# Capybara settings (not covered by Rails system tests)

# Use a hostname accessible from the outside world
# (Required for running tests in Docker)
Capybara.server_host = `hostname`.strip&.downcase || "0.0.0.0"
Capybara.app_host = "http://#{Capybara.server_host}"

# Don't wait too long in `have_xyz` matchers
Capybara.default_max_wait_time = 2

Expand Down
36 changes: 8 additions & 28 deletions spec/system/support/cuprite_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,21 @@
# Cuprite is a modern Capybara driver which uses Chrome CDP API
# instead of Selenium & co.
# See https://github.com/rubycdp/cuprite

REMOTE_CHROME_URL = ENV["CHROME_URL"]
REMOTE_CHROME_HOST, REMOTE_CHROME_PORT =
if REMOTE_CHROME_URL
URI.parse(REMOTE_CHROME_URL).yield_self do |uri|
[uri.host, uri.port]
end
end

# Check whether the remote chrome is running and configure the Capybara
# driver for it.
remote_chrome =
begin
if REMOTE_CHROME_URL.nil?
false
else
Socket.tcp(REMOTE_CHROME_HOST, REMOTE_CHROME_PORT, connect_timeout: 1).close
true
end
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, SocketError
false
end

remote_options = remote_chrome ? {url: REMOTE_CHROME_URL} : {}

require "capybara/cuprite"

Capybara.register_driver(:cuprite) do |app|
Capybara::Cuprite::Driver.new(
app,
**{
window_size: [1200, 800],
browser_options: remote_chrome ? {"no-sandbox" => nil} : {},
inspector: true
}.merge(remote_options)
browser_options: {},
# Increase Chrome startup timeout for CI
process_timeout: 10,
inspector: true,
# Allow running Chrome in a headful mode by setting HEADLESS env
# var to a falsey value
headless: !ENV["HEADLESS"].in?(%w[n 0 no false])
}
)
end

Expand Down

0 comments on commit b5cace4

Please sign in to comment.