如何配置 Heroku CI 来运行系统测试?
这是我的 app.json,其中包含了我认为必要的构建包:
{
"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。
最佳答案
您是否正确设置了网络驱动程序以找到如上所述的正确二进制文件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
- 然后,通过将自定义 Chrome 驱动程序添加到您的
application_system_test_case.rb
中,告诉您的系统测试使用您的自定义 Chrome 驱动程序。
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :heroku_chrome
end
关于heroku-toolbelt - 如何在 Heroku CI 中运行 Rails 系统测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59361503/