├── .gitignore ├── LICENSE ├── README.md └── latest ├── Dockerfile └── docker-entrypoint.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | /log 3 | /tmp 4 | .env 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Nikita Bulai 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ruby-chromedriver 2 | 3 | [![Docker Pulls](https://img.shields.io/docker/pulls/nbulai/ruby-chromedriver.svg)](https://hub.docker.com/r/nbulai/ruby-chromedriver/) 4 | [![Docker Stars](https://img.shields.io/docker/stars/nbulai/ruby-chromedriver.svg)](https://hub.docker.com/r/nbulai/ruby-chromedriver/) 5 | 6 | Ruby 3.1.x, Chrome / [Chrome driver](https://sites.google.com/chromium.org/driver/), NodeJS on 7 | Docker for [Capybara](https://github.com/teamcapybara/capybara)/[Cucumber](https://github.com/cucumber/cucumber) specs. 8 | 9 | Based on official Ruby image and uses official stable Chrome repository. Uses X virtual framebuffer (Xvfb) 10 | for keycode conversions. 11 | 12 | Can be used for Continuous Integration or Delivery (CI/CD) pipelines (like GitLab) instead of Qt and PhantomJS: 13 | 14 | # CI/CD Configuration 15 | 16 | Example of GitLab CI configuration for Ruby on Rails project with Cucumber using the image 17 | (read https://about.gitlab.com/2017/12/19/moving-to-headless-chrome/): 18 | 19 | ```yaml 20 | cucumber: 21 | stage: test 22 | image: 'nbulai/ruby-chromedriver:latest' 23 | variables: 24 | RAILS_ENV: test 25 | script: 26 | - chromedriver -v # to check version 27 | - ... 28 | - bin/cucumber 29 | artifacts: 30 | paths: 31 | - coverage/ 32 | only: 33 | - main 34 | ``` 35 | 36 | If you need some specific screen size for testing, then you can pass it as an `SCREEN` environment variable: 37 | 38 | `docker run -e SCREEN="1280x1024x16" -t -i --rm nbulai/ruby-chromedriver:latest bash` 39 | 40 | Don't forget to configure your Cucumber/Capybara to use Chrome as a driver (see instruction below). 41 | 42 | First install it locally to run your test-suite (if you will run tests on the dev machine): 43 | 44 | ```bash 45 | # add Google public key 46 | wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - 47 | # add Google Chrome stable repository to sources 48 | echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list 49 | sudo apt-get update 50 | # install Chrome and it's driver 51 | sudo apt-get install google-chrome-stable chromium-chromedriver 52 | sudo ln -s /usr/lib/chromium-browser/chromedriver /usr/bin/chromedriver 53 | # check if all is OK 54 | chromedriver -v 55 | ``` 56 | 57 | Add gem `selenium-webdriver` to your `Gemfile`: 58 | 59 | ```ruby 60 | group :test do 61 | # ... 62 | gem 'selenium-webdriver' 63 | end 64 | ``` 65 | 66 | And then edit `features/support/env.rb` (or other config file): 67 | 68 | ```ruby 69 | # ... 70 | 71 | Capybara.register_driver(:headless_chrome) do |app| 72 | capabilities = Selenium::WebDriver::Remote::Capabilities.chrome( 73 | # Add 'no-sandbox' arg if you have an "unknown error: Chrome failed to start: exited abnormally" 74 | # @see https://github.com/SeleniumHQ/selenium/issues/4961 75 | chromeOptions: { args: %w[headless disable-gpu no-sandbox] } 76 | ) 77 | 78 | Capybara::Selenium::Driver.new(app, browser: :chrome, desired_capabilities: capabilities) 79 | end 80 | 81 | Capybara.javascript_driver = :headless_chrome 82 | 83 | # ... 84 | ``` 85 | 86 | That's all. Run `bin/cucumber` to check your tests. 87 | 88 | ## License 89 | 90 | This repo content is released under the [MIT License](http://www.opensource.org/licenses/MIT). 91 | 92 | Copyright (c) 2017- Nikita Bulai (bulajnikita@gmail.com). 93 | -------------------------------------------------------------------------------- /latest/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG RUBY_VERSION=3.1.3 2 | FROM ruby:${RUBY_VERSION} 3 | 4 | MAINTAINER Nikita Bulai 5 | 6 | ENV DEBIAN_FRONTEND noninteractive 7 | ENV CHROMIUM_DRIVER_VERSION 109.0.5414.74 8 | ENV CHROME_VERSION 109.0.5414.119-1 9 | 10 | # Install dependencies & Chrome 11 | SHELL ["/bin/bash", "-o", "pipefail", "-c"] 12 | RUN apt-get update && apt-get -y --no-install-recommends install zlib1g-dev liblzma-dev wget xvfb unzip libgconf-2-4 libnss3 nodejs \ 13 | && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \ 14 | && echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \ 15 | && apt-get update && apt-get -y --no-install-recommends install google-chrome-stable=$CHROME_VERSION \ 16 | && rm -rf /var/lib/apt/lists/* 17 | 18 | # Install Chrome driver 19 | RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/$CHROMIUM_DRIVER_VERSION/chromedriver_linux64.zip \ 20 | && unzip /tmp/chromedriver.zip chromedriver -d /usr/bin/ \ 21 | && rm /tmp/chromedriver.zip \ 22 | && chmod ugo+rx /usr/bin/chromedriver \ 23 | && apt-mark hold google-chrome-stable 24 | 25 | ADD docker-entrypoint.sh / 26 | ENTRYPOINT ["/docker-entrypoint.sh"] 27 | -------------------------------------------------------------------------------- /latest/docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | SCREEN="${SCREEN:-1280x1024x16}" 5 | echo "Starting X virtual framebuffer (Xvfb) for $SCREEN screen in background..." 6 | Xvfb -ac :99 -screen 0 $SCREEN > /dev/null 2>&1 & 7 | export DISPLAY=:99 8 | 9 | exec "$@" 10 | --------------------------------------------------------------------------------