[英]Gitlab CI Config for Rails System Tests with Selenium and Headless Chrome
我正在嘗試為一個非常簡單的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有關),因為一旦我省略了系統測試,一切都完美無缺。
順便說一句,如果任何人有任何更好的配置文件來實現相同的目標,我很想看到其他人做什么。 提前致謝。
在如何將服務鏈接到作業和訪問服務時,它表示如果您啟動tutum/wordpress
容器(通過service
節);
將啟動
tutum/wordpress
,您可以從兩個主機名下的構建容器中訪問它,以便從中進行選擇:
- tutum,WordPress的
- tutum__wordpress
注意:帶下划線的主機名不具有RFC有效性,可能會導致第三方應用程序出現問題
所以這就是我的進展方式:
http://selenium-standalone-chrome:4444/wd/hub
雖然這看起來像是一個低概率的解決方案.. SELENIUM_URL
。 它設置正確嗎? standalone-chrome
會出現嗎? ping
或nslookup
。 selenium-standalone-chrome
(或替代品)是否可以解決? 看起來它確實如此,否則我們會得到一個“ 主機名未知 ”而不是“ 拒絕連接 ”,但你永遠不會太確定。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.