我在 rails 3.1.0 应用程序中使用 Capybara(同时使用 1.1.1 和 1.1.2)。我正在尝试使用 chromedriver 让 Capybara 运行以进行集成测试。当我运行测试套件时,测试用例失败并出现此错误:
Selenium::WebDriver::Error::WebDriverError: unable to connect to chromedriver http://127.0.0.1:53468
当我不使用 chromedriver firefox 也将无法工作。奇怪的是,当我从irb
(而不是 rails 控制台)使用 capybara 时,它工作正常。但是,当我尝试将它与加载的 Rails 应用程序一起使用时,总是会发生上述错误。
我想这与我正在加载的依赖项有关,因为我在另一个(Rails 2)项目中运行 Capybara 很好。
如果有帮助,这里是我的 gemfile:
source 'http://rubygems.org'
gem 'rails', '3.1.0'
gem 'mysql2', '~> 0.3.6'
gem 'pg'
gem 'json'
gem 'alchemist'
gem "rails-backbone"
group :assets do
gem 'sass-rails', "~> 3.1.0.rc"
gem 'coffee-rails', "~> 3.1.0.rc"
gem 'uglifier'
end
gem 'jquery-rails'
group :test, :development do
gem 'jasmine'
gem 'capybara'
gem 'launchy'
gem 'rspec'
gem 'rspec-rails'
gem "factory_girl_rails", "~> 1.1"
end
我的规范助手看起来像这样:
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
需要“水豚/导轨”
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
Capybara.default_driver = :selenium
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.mock_with :rspec
end
感谢您的任何想法。
PS。不确定这是否有帮助,但是当我使用chromedriver-helper
gem 时,我得到了这个错误:
no such file to load -- {"sessionId":"bcdf4c348c8f976cbe20f98120a456d0","status":0,"value":{"acceptSslCerts":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome.chromedriverVersion":"19.0.1068.0","chrome.nativeEvents":false,"cssSelectorsEnabled":true,"databaseEnabled":false,"handlesAlerts":true,"javascriptEnabled":true,"locationContextEnabled":false,"nativeEvents":true,"platform":"mac","rotatable":false,"takesScreenshot":true,"version":"18.0.1025.168","webStorageEnabled":false}}