簡體   English   中英

使用Selenium和無頭Chrome進行Rails系統測試的Gitlab CI配置

[英]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會出現嗎?
  • 在某處添加pingnslookup selenium-standalone-chrome (或替代品)是否可以解決? 看起來它確實如此,否則我們會得到一個“ 主機名未知 ”而不是“ 拒絕連接 ”,但你永遠不會太確定。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM