I'm trying to set up continuous Gitlab integration for a very simple Rails project and, despite all my searching, cannot find any workable solution for getting system tests to work using headless Chrome.
Here's my .gitlab-ci.yml
file:
image: 'ruby:2.6.3'
before_script:
- curl -sL https://deb.nodesource.com/setup_11.x | bash -
- apt-get install -y nodejs
- apt-get install -y npm
- gem install bundler --conservative
- bundle install
- npm install -g yarn
- yarn install
stages:
- test
test:
stage: test
variables:
MYSQL_HOST: 'mysql'
MYSQL_DATABASE: 'cwrmb_test'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
SYSTEM_EMAIL: 'test@example.com'
REDIS_URL: 'redis://redis:6379/'
SELENIUM_URL: "http://selenium__standalone-chrome:4444/wd/hub"
services:
- redis:latest
- selenium/standalone-chrome:latest
- name: mysql:latest
command: ['--default-authentication-plugin=mysql_native_password']
script:
- RAILS_ENV=test bin/rails db:setup
- bin/rails test:system
Here's my application_system_test_case.rb
:
require 'test_helper'
def selenium_options
driver_options = {
desired_capabilities: {
chromeOptions: {
args: %w[headless disable-gpu no-sandbox disable-dev-shm-usage]
}
}
}
driver_options[:url] = ENV['SELENIUM_URL'] if ENV['SELENIUM_URL']
driver_options
end
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :chrome, screen_size: [1400, 1400], options: selenium_options
end
However, this configuration yields the following error for every system test:
Selenium::WebDriver::Error::UnknownError: java.net.ConnectException: Connection refused (Connection refused)
I don't believe there are any other errors (to do with Redis or MySQL) in this configuration file, because as soon as I omit system tests, everything works perfectly.
By the way, if anyone has any better configuration files for achieving the same goal, I would love to see what others do. Thanks in advance.