我在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控制台)的水豚时,它运行正常。但是,当我尝试在加载我的Rails应用程序时使用它时,总会发生上述错误。
我想这与我正在加载的依赖项有关,因为我在另一个(Rails 2)项目中运行Capybara很好。
如果有帮助,这是我的宝石文件:
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
我的规格Helper看起来像这样:
# 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 / rails'
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}}
答案 0 :(得分:2)
答案 1 :(得分:0)
我们还必须将javascript_driver设置为:chrome
即。特征/支持/ chrome.rb:
# Use Chrome for Selenium (@javascript) browser-based tests in Capybara.
# Chromedriver, the Chromium project's selenium webdriver adapter, must
# be installed on the test server. To ease the installation and use of
# chromedriver, the chromedriver-helper gem is specified in the Gemfile.
#
# Updating Chromedriver
# =====================
# If you'd like to force-upgrade to the latest version of chromedriver,
# run the script 'chromedriver-update' that comes packaged with this
# gem.
# This might be necessary on platforms on which Chrome auto-updates,
# which has been known to introduce incompatibilities with older versions
# of chromedriver.
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
# The chromedriver-helper docs don't list this as a requirement.
# We only know about it from other chrome driver docs.
Capybara.javascript_driver = :chrome