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

标签 heroku-toolbelt heroku-cli

如何配置 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

  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
  • 然后,通过将自定义 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/

    相关文章:

    heroku-toolbelt - Heroku Toolbelt PPA 更新检查失败

    Heroku 获取特定日期的日志

    git - 如何将长时间运行的 `git push` 修复为 Heroku 远程响应 `504 GATEWAY_TIMEOUT` ?

    Heroku 登录错误 : self signed certificate in certificate chain

    javascript - 从 Heroku CLI 运行脚本

    docker - Heroku:找不到 docker 入口点

    docker - Heroku:如何在 gitlab CI/CD 中发布现有图像?

    heroku 客户端内部错误 - 控制台超时

    linux - Heroku toolbelt 安装后 "Warning! PATH is not properly set up"& "RVM is not a function"

    heroku - Heroku 中的进程类型和 Dynos 有什么区别