Webdrivers::BrowserNotFound: 找不到 Chrome 二进制文件

Posted

技术标签:

【中文标题】Webdrivers::BrowserNotFound: 找不到 Chrome 二进制文件【英文标题】:Webdrivers::BrowserNotFound: Failed to find Chrome binary 【发布时间】:2021-11-17 19:30:56 【问题描述】:

我正在尝试运行系统测试并在此错误中继续运行:

rails 中止! 。 /home/hasani/PROJECTS/hasani_pos/test/application_system_test_case.rb:4:in <class:ApplicationSystemTestCase>' /home/hasani/PROJECTS/hasani_pos/test/application_system_test_case.rb:3:in ' /home/hasani/PROJECTS/hasani_pos/test/system/items_test.rb:1:in <main>' /home/hasani/PROJECTS/hasani_pos/bin/rails:5:in ' /home/hasani/PROJECTS/hasani_pos/bin/spring:10:in block in <top (required)>' /home/hasani/PROJECTS/hasani_pos/bin/spring:7:in ' 任务:TOP => 测试:系统 (通过使用 --trace 运行任务查看完整跟踪)

items_test.rb

require "application_system_test_case"

class ItemsTest < ApplicationSystemTestCase
  test "visiting the index" do
    visit '/items'
    assert_selector "h1", text: "Items"
  end

  test "creating an item" do
    visit '/items'
    click_on "Create Item"
    assert_template 'new'
  end
end

test_helper.rb

ENV['RAILS_ENV'] ||= 'test'
require_relative "../config/environment"
require "rails/test_help"
require "minitest/reporters"
require 'capybara/rails'
require 'capybara/minitest'
require 'webdrivers'
Minitest::Reporters.use!

class ActiveSupport::TestCase
  # Run tests in parallel with specified workers
  parallelize(workers: :number_of_processors)

  # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
  fixtures :all

  def is_logged_in?
    !session[:user_id].nil?
  end

  # Make the Capybara DSL available in all integration tests
  include Capybara::DSL
  # Make `assert_*` methods behave like Minitest assertions
  include Capybara::Minitest::Assertions

  # Reset sessions and driver between tests
  teardown do
    Capybara.reset_sessions!
    Capybara.use_default_driver
  end
end

index.html.erb

<%= provide(:title, 'Item Index') %>
<h1>Item Index</h1>
  
  <a href="/add" class="btn btn-primary">Create Item</a>
  
  <div class="row">
    <div class="col-md-6 col-md-offset-3">
      <table>
        <tr>
          <thead>
            <th>Name</th>
            <th>Description</th>
            <th>Price</th>
          </thead>
        </tr>
        <% @items.each do |item| %>
          <tr>
            <td><%= item.name %></td>
            <td><%= item.description %></td>
            <td><%= item.price %></td>
            <td>
              <%= link_to "Edit", edit_item_path(item) %>
              <%= link_to "Delete", 
                          item_path(item), method: :delete, 
                          "data-confirm": "Are you sure you want to delete?" %>
            </td>
          </tr>
        <% end %>  
      </table>
    </div>
  </div>

new.html.erb

<h1>Create Item</h1>

<div class="row">
  <div class="col-md-6 col-md-offset-3">
    <%= form_for(@item) do |f| %>
    <%= render 'shared/error_msg' %>  

      <%= f.label :name %>
      <%= f.text_field :name %>
   
      <%= f.label :description %>
      <%= f.text_area :description %>
      
      <%= f.label :price %>
      <%= f.number_field :price %>
      
      <%= f.submit "Create Item", class: "btn btn-primary" %>
    <% end %>
  </div>
</div>

【问题讨论】:

【参考方案1】:

基本上,错误的意思是网络驱动程序无法找到谷歌浏览器。确保已将其安装在机器上的正确位置。

这个issue 更详细地介绍了它,除了是 ruby​​ over python:

【讨论】:

以上是关于Webdrivers::BrowserNotFound: 找不到 Chrome 二进制文件的主要内容,如果未能解决你的问题,请参考以下文章