如何配置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。
答案 0 :(得分:2)
您是否正确设置了网络驱动程序以找到正确的二进制文件,如on the official UAT wiki page of heroku所述?
将gem 'webdrivers'
添加到您的Gemfile。
将以下代码段添加到您的test_helper.rb(如on heroku buildback wiki和webdrivers 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
application_system_test_case.rb
来告诉系统测试使用自定义chrome驱动程序。class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :heroku_chrome
end