Ruby 3.1.x, Chrome / Chrome driver, NodeJS on Docker for Capybara/Cucumber specs.
Based on official Ruby image and uses official stable Chrome repository. Uses X virtual framebuffer (Xvfb) for keycode conversions.
Can be used for Continuous Integration or Delivery (CI/CD) pipelines (like GitLab) instead of Qt and PhantomJS:
Example of GitLab CI configuration for Ruby on Rails project with Cucumber using the image (read https://about.gitlab.com/2017/12/19/moving-to-headless-chrome/):
cucumber:
stage: test
image: 'nbulai/ruby-chromedriver:latest'
variables:
RAILS_ENV: test
script:
- chromedriver -v # to check version
- ...
- bin/cucumber
artifacts:
paths:
- coverage/
only:
- main
If you need some specific screen size for testing, then you can pass it as an SCREEN
environment variable:
docker run -e SCREEN="1280x1024x16" -t -i --rm nbulai/ruby-chromedriver:latest bash
Don't forget to configure your Cucumber/Capybara to use Chrome as a driver (see instruction below).
First install it locally to run your test-suite (if you will run tests on the dev machine):
# add Google public key
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
# add Google Chrome stable repository to sources
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
sudo apt-get update
# install Chrome and it's driver
sudo apt-get install google-chrome-stable chromium-chromedriver
sudo ln -s /usr/lib/chromium-browser/chromedriver /usr/bin/chromedriver
# check if all is OK
chromedriver -v
Add gem selenium-webdriver
to your Gemfile
:
group :test do
# ...
gem 'selenium-webdriver'
end
And then edit features/support/env.rb
(or other config file):
# ...
Capybara.register_driver(:headless_chrome) do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
# Add 'no-sandbox' arg if you have an "unknown error: Chrome failed to start: exited abnormally"
# @see https://github.com/SeleniumHQ/selenium/issues/4961
chromeOptions: { args: %w[headless disable-gpu no-sandbox] }
)
Capybara::Selenium::Driver.new(app, browser: :chrome, desired_capabilities: capabilities)
end
Capybara.javascript_driver = :headless_chrome
# ...
That's all. Run bin/cucumber
to check your tests.
This repo content is released under the MIT License.
Copyright (c) 2017- Nikita Bulai ([email protected]).