本文介绍了Firefox是默认设置,但仍会出现WebDriverError:无法连接到chromedriver 127.0.0.1:9515的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是第一次设置Capybara,默认情况下它似乎是在调用Chrome而不是Firefox。

I'm setting up Capybara for the first time and it seems to be calling Chrome instead of Firefox by default.

起初,我遇到了webdriver错误:

At first I was getting the webdriver error:

我可以通过添加 gem'chromedriver-helper'

我还尝试将其添加到spec_helper和rails_helper中:

I also tried adding this to both spec_helper and rails_helper:

Capybara.register_driver :selenium do |app|
  Capybara::Selenium::Driver.new(app, browser: :firefox)
end

我能够确认Rails能够成功调用firefox,因为在开始测试时,rails_helper中的以下命令确实成功启动了Firefox(但未采取任何进一步的措施)(根据评论,我后来删除了它)

I was able to confirm that rails was able to successfully call firefox because the following command in rails_helper does successfully launch Firefox (but does not take any further action) when I start the test (as per comments, I later removed this command).

RSpec.configure do |config|
    driver = Selenium::WebDriver.for :firefox
end

I'我在另一台机器和不同的Rails应用程序上遇到了相同的错误(在Capybara的第一遍中也没有设置geckodriver)

I'm getting the same error on a separate machine and on a different rails app (also didn't have geckodriver set-up on the first pass of Capybara)

我的理解是默认情况下,Capybara应该调用Firefox。我似乎找不到第二个配置。有没有人知道我在哪里可以找到调用chrome的行?

My understanding is that Capybara should call Firefox by default. There seems to be a second configuration somewhere that I can't find. Does anyone have an idea of where I might find the line that is calling chrome?

推荐答案

从您提供的日志文件中,我们可以看到您正在使用Rails 5.1,RSpec 3.8和Capybara 2.18。由于该日志还包含 actionpack-5.1.6 / lib / action_dispatch / system_testing / driver.rb,因此我们可以知道您正在编写系统测试/规范(通过rspec-rails)。系统测试所使用的驱动程序由driven_by 方法控制system-specs / system-spec rel = nofollow noreferrer> RSpec系统规范文档,默认情况下使用Rails注册的:selenium 驱动程序,该驱动程序配置为使用Chrome。如所述,您可以切换到Firefox通过指定

From the log file you provided we can see that you're using Rails 5.1, RSpec 3.8 and Capybara 2.18. Since the log also includes "actionpack-5.1.6/lib/action_dispatch/system_testing/driver.rb" we can tell that you're writing system tests/specs (through rspec-rails). The driver used by system tests is controlled by the driven_by method as documented in the RSpec system spec docs and by default uses the Rails registered :selenium driver which is configured to use Chrome. As documented in the Rails System Test docs you can switch to Firefox by specifying

driven_by :selenium, using: :firefox

此外,水豚2.18在这一点上已经过时了。如果您打算使用最新版本的Firefox / Chrome,则可能要更新到最新版本(截至目前为3.6)。

Additionally, Capybara 2.18 is pretty much obsolete at this point. You probably want to update to the latest version (3.6 as of now) if you plan on using the latest versions of Firefox/Chrome.

这篇关于Firefox是默认设置,但仍会出现WebDriverError:无法连接到chromedriver 127.0.0.1:9515的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 21:39