Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cukes via Docker - selenium (Chrome in a container) #385

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,24 @@ services:
- .:/app
ports:
- "3000:3000"
- "4000:4000"
- "35729:35729"
environment:
- HOSTNAME=localhost:3000
- DOCKERIZED=true
depends_on:
- postgresql

selenium_chrome:
image: selenium/standalone-chrome-debug
logging:
driver: none
ports:
- 5900:5900

selenium_firefox:
image: selenium/standalone-firefox-debug
logging:
driver: none
ports:
- 5900:5900
52 changes: 47 additions & 5 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,53 @@
)
end

Capybara.javascript_driver = if ENV['CAPYBARA_JAVASCRIPT_DRIVER']
ENV['CAPYBARA_JAVASCRIPT_DRIVER'].to_sym
else
:selenium
end
Capybara.register_driver :selenium_chrome_in_container do |app|
Capybara::Selenium::Driver.new app, browser: :remote, url: 'http://selenium_chrome:4444/wd/hub', desired_capabilities: :chrome
end

Capybara.register_driver :headless_selenium_chrome_in_container do |app|
Capybara::Selenium::Driver.new(
app,
browser: :remote,
url: 'http://selenium_chrome:4444/wd/hub',
desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome(chromeOptions: { args: %w[headless disable-gpu] })
)
end

Capybara.register_driver :selenium_firefox_in_container do |app|
Capybara::Selenium::Driver.new(app,
browser: :remote,
url: 'http://selenium_firefox:4444/wd/hub',
desired_capabilities: :firefox)
end

Capybara.register_driver :headless_selenium_firefox_in_container do |app|
Capybara::Selenium::Driver.new(
app,
browser: :remote,
url: 'http://selenium_firefox:4444/wd/hub',
desired_capabilities: Selenium::WebDriver::Remote::Capabilities.firefox(
opts: { args: ['-headless'] }
)
)
end

if ENV['CAPYBARA_JAVASCRIPT_DRIVER']
Capybara.javascript_driver = ENV['CAPYBARA_JAVASCRIPT_DRIVER'].to_sym
else
Capybara.javascript_driver = :selenium
# Capybara.javascript_driver = :headless_selenium_chrome_in_container
# Capybara.javascript_driver = :headless_selenium_firefox_in_container
# Capybara.javascript_driver = :selenium_firefox_in_container

Capybara.server_host = '0.0.0.0'

Capybara.server_port = 4000

Capybara.app_host = 'http://app:4000'

Capybara.always_include_port = true
end

if ENV['BROWSER']
DatabaseCleaner.strategy = :truncation
Expand Down
15 changes: 15 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
require 'paper_trail/frameworks/rspec'
require 'factory_bot'
require 'faker'
require_relative './support/capybara.rb'

# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
Expand Down Expand Up @@ -48,6 +49,20 @@
# arbitrary gems may also be filtered via:
# config.filter_gems_from_backtrace("gem name")
config.include FactoryBot::Syntax::Methods

config.before(:each, type: :system, js: true) do
driven_by :selenium_chrome_in_container

Capybara.server_host = '0.0.0.0'

Capybara.server_port = 4000

Capybara.app_host = 'http://app:4000'
end

config.before(:each, type: :system) do
driven_by :rack_test
end
end

Shoulda::Matchers.configure do |config|
Expand Down
17 changes: 17 additions & 0 deletions spec/support/capybara.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'selenium/webdriver'

Capybara.register_driver :selenium_chrome_in_container do |app|
Capybara::Selenium::Driver.new app,
browser: :remote,
url: 'http://selenium_chrome:4444/wd/hub',
desired_capabilities: :chrome
end

Capybara.register_driver :headless_selenium_chrome_in_container do |app|
Capybara::Selenium::Driver.new app,
browser: :remote,
url: 'http://selenium_chrome:4444/wd/hub',
desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: { args: %w[headless disable-gpu] }
)
end