【发布时间】:2019-07-04 22:40:30
【问题描述】:
我正在尝试为一个非常简单的 Rails 项目设置持续的 Gitlab 集成,尽管我进行了所有搜索,但找不到任何可行的解决方案来使用无头 Chrome 进行系统测试。
这是我的.gitlab-ci.yml 文件:
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
这是我的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
但是,此配置会为每个系统测试产生以下错误:
Selenium::WebDriver::Error::UnknownError: java.net.ConnectException: Connection refused (Connection refused)
我不相信这个配置文件中还有任何其他错误(与 Redis 或 MySQL 有关),因为只要我省略系统测试,一切都会正常运行。
顺便说一句,如果有人有更好的配置文件来实现相同的目标,我很想看看其他人是怎么做的。提前致谢。
【问题讨论】:
标签: ruby-on-rails selenium-webdriver gitlab-ci google-chrome-headless system-testing