Skip to content

Instantly share code, notes, and snippets.

@Yenwod
Forked from julianrubisch/.gitlab-ci.yml
Created September 17, 2021 16:13
Show Gist options
  • Save Yenwod/24597570bd53e7b3e2e15356b6a62aba to your computer and use it in GitHub Desktop.
Save Yenwod/24597570bd53e7b3e2e15356b6a62aba to your computer and use it in GitHub Desktop.
Gitlab CI Config for Minitest/system tests
image: "ruby:2.7"
services:
- postgres
- redis:latest
variables:
RAILS_ENV: test
POSTGRES_DB: my_app_test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: "password"
DATABASE_URL: "postgresql://postgres:password@postgres:5432/my_app_test"
SELENIUM_URL: http://selenium__standalone-chrome:4444/wd/hub
before_script:
- apt-get update -qq && apt-get install -y -qq nodejs
# Install yarn as outlined in (https://yarnpkg.com/lang/en/docs/install/#alternatives-stable)
- curl -o- -L https://yarnpkg.com/install.sh | bash
# Make available in the current terminal
- export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
- node -v
- yarn -v
- ruby -v
- which ruby
- gem install bundler --no-document
- bundle install --jobs $(nproc) "${FLAGS[@]}" --path vendor
- yarn install
# Database setup
- bin/rails db:setup
test:
stage: test
cache:
paths:
- node_modules/
- .yarn
- vendor
script:
- bundle exec rails test
only:
- master
- merge_requests
system_test:
stage: test
cache:
paths:
- node_modules/
- .yarn
- vendor
- public/packs-test
artifacts:
when: on_failure
paths:
- tmp/screenshots
- /tmp/chrome.log
- log/test.log
expire_in: 1 week
script:
- bundle exec rails test:system
only:
- master
- merge_requests
services:
- postgres
- redis:latest
- selenium/standalone-chrome:latest
require "test_helper"
Capybara.server = :puma, {Silent: true}
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
if ENV['SELENIUM_URL']
# Specify the driver (remote selenium, read: CI)
driven_by :selenium, using: :chrome, screen_size: [1920, 1080],
options: {url: ENV["SELENIUM_URL"],
args: %w[headless disable-popup-blocking disable-gpu no-sandbox
disable-dev-shm-usage window-size=1920,1080
enable-features=NetworkService],}
# Make the test app listen to outside requests, for the remote Selenium instance.
Capybara.server_host = "0.0.0.0"
else
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]
end
setup do
if ENV['SELENIUM_URL']
# Get the application container's IP
ip = Socket.ip_address_list.detect(&:ipv4_private?).ip_address
# Use the IP instead of localhost so Capybara knows where to direct Selenium
host! "http://#{ip}:#{Capybara.server_port}"
end
end
end
# ...
group :test do
gem 'webdrivers', require: !ENV['SELENIUM_URL']
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment