如何在Heroku CI中运行Rails系统测试

如何配置Heroku CI以运行系统测试?

这是我的app.json,其中包含了我认为是必要的buildpacks:

    {
  "environments": {
    "test": {
      "scripts": {
        "test-setup": "bin/rails assets:precompile","test": "bin/rails test:system"
      },"addons":[
        "heroku-postgresql:in-dyno"
      ],"buildpacks": [
        { "url": "https://github.com/heroku/heroku-buildpack-google-chrome" },{ "url": "heroku/nodejs" },{ "url": "heroku/ruby"}
      ]
    }
  }
}

但是当我部署时,出现以下错误:

-----> Running test command `bin/rails test:system`...
rails aborted!
Webdrivers::BrowserNotFound: Failed to find Chrome binary.

我怀疑我缺少一些非常基本的东西。...

我正在运行Rails 6.0.1和Ruby 2.6.3。

wgbmuziyo 回答:如何在Heroku CI中运行Rails系统测试

您是否正确设置了网络驱动程序以找到正确的二进制文件,如on the official UAT wiki page of heroku所述?

  1. gem 'webdrivers'添加到您的Gemfile。

  2. 将以下代码段添加到您的test_helper.rb(如on heroku buildback wikiwebdrivers wiki所述):

require 'webdrivers' # Make sure webdrivers are loaded.

chrome_bin = ENV['GOOGLE_CHROME_SHIM'] if ENV['GOOGLE_CHROME_SHIM'].present?

chrome_capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
  chromeOptions: {
    # You may want to use a different args
    args: %w[headless disable-gpu window-size=1400x1400],binary: chrome_bin
  }
)

Capybara.register_driver :heroku_chrome do |app|
  Capybara::Selenium::Driver.new(app,browser: :chrome,desired_capabilities: chrome_capabilities)
end
  1. 然后通过将其添加到application_system_test_case.rb来告诉系统测试使用自定义chrome驱动程序。
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  driven_by :heroku_chrome
end
本文链接:https://www.f2er.com/2911542.html

大家都在问