How to open a local instance of Chrome browser after cucumber command in a container?

  automated-tests, capybara, docker, ruby, testing

I have a ruby test automation project with capybara running in a container in headless mode. I would like, when running inside the container, to open the browser on the host machine to start automation.

The automation project is inside the container. Container headless mode is working. I want the host to take charge of opening the Chrome browser and automating the tests.

My env.rb file:

require 'capybara'
require 'capybara/dsl'
require 'capybara/cucumber'
require 'selenium-webdriver'
require 'rspec'
require 'site_prism'
require 'capybara/rspec/matchers'
require 'capybara/rspec/matcher_proxies'
require 'webdrivers'
require 'builder'
require 'pry'

Capybara.register_driver :chrome_headless do |app|
  Capybara::Selenium::Driver.new app, browser: :chrome,
  options: Selenium::WebDriver::Chrome::Options.new(args: %w[headless disable-gpu])
end

Capybara.configure do |config|
  config.default_driver = :selenium_chrome
end

Capybara.register_driver :headless_chrome do |app|
  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
      'goog:chromeOptions': { args: %w(no-sandbox headless disable-gpu window-size=1280,1024 disable-features=VizDisplayCompositor) } )
  Capybara::Selenium::Driver.new(app, browser: :chrome, desired_capabilities: capabilities)
end

Capybara.register_driver :chrome_headless do |app|
  options = Selenium::WebDriver::Chrome::Options.new
  options.add_argument('--window-size=1920,1080')
  options.add_argument('--headless')
  options.add_argument('--no-sandbox')
  options.add_argument('--disable-dev-shm-usage')

  Capybara::Selenium::Driver.new(app,
                                 browser: :chrome,
                                 options: options)
end

Capybara.configure do |config|
  Capybara.javascript_driver = :headless_chrome
  #Capybara.default_driver = :chrome_headless
  Capybara.default_driver = :selenium_chrome
  config.default_max_wait_time = 15
  config.app_host = 'https://www.google.com'
end

Source: Docker Questions

LEAVE A COMMENT