Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails “如何修复”;Selenium::WebDriver::Error::WebDriverError:chrome无法访问”;在WSL2中_Ruby On Rails_Ruby_Selenium_Capybara_Windows Subsystem For Linux - Fatal编程技术网

Ruby on rails “如何修复”;Selenium::WebDriver::Error::WebDriverError:chrome无法访问”;在WSL2中

Ruby on rails “如何修复”;Selenium::WebDriver::Error::WebDriverError:chrome无法访问”;在WSL2中,ruby-on-rails,ruby,selenium,capybara,windows-subsystem-for-linux,Ruby On Rails,Ruby,Selenium,Capybara,Windows Subsystem For Linux,我正在尝试使用WSL2到rails应用程序,在RSpec运行时出现以下错误: Selenium::WebDriver::Error::WebDriverError: chrome not reachable (Session info: headless chrome=77.0.3865.75) 有人知道怎么修吗 My capybara.rb: require "capybara/rails" require "selenium-we

我正在尝试使用WSL2到rails应用程序,在RSpec运行时出现以下错误:

Selenium::WebDriver::Error::WebDriverError:
              chrome not reachable
                (Session info: headless chrome=77.0.3865.75)
有人知道怎么修吗

My capybara.rb:

require "capybara/rails"
require "selenium-webdriver"

Capybara.default_max_wait_time = 10
Capybara.register_driver :chrome do |app|
  options = Selenium::WebDriver::Chrome::Options.new(
    args: %w[headless no-sandbox]
  )
  Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end

Capybara.javascript_driver = :chrome
Capybara.server = :puma, { Silent: true }

我将路径放在env变量中,以达到我的chromewebdriver二进制文件,在本文后面是“”,什么都没有

我只是用下面的代码来修复它

 Capybara.register_driver :chrome do |app|
        options = Selenium::WebDriver::Chrome::Options.new(args: %w[
          headless no-sandbox disable-gpu window-size=1920x1080
        ])
          Capybara::Selenium::Driver.new(app,
            browser: :chrome,
            desired_capabilities: {
              "chromeOptions" => {
                w3c: false
              }
            }
          )
      end

请让我知道这是否是解决您的问题的方法

您如何初始化web驱动程序?这是每次初始化web驱动程序时发生的还是间歇性的?每次我运行测试时都会发生这种情况,当它使用capybara访问views测试时,就会发生这种情况!我把我的capybara.rb放在上面,但我的问题是在WSLCA中使用chromedriver在capybara中进行基本的make works测试,你能发布其中一个失败的测试的代码吗?@GregBurghardt这个错误只是在视图测试中发生的,我在其他论坛中发现这是因为WSL试图在后台chrome中使用,但WSL没有“显示”这会导致所有视图测试失败,并出现以下错误:Selenium::WebDriver::error::WebDriverError:chrome不可访问(会话信息:headless chrome=77.0.3865.75)使用linux环境进行测试是可以的,但在WSL2中无法工作,并且无法使用WSL2中的chromedriver解决此问题