3

我在 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-helpergem 时,我得到了这个错误:

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}}
4

2 回答 2

2

在 spec_helper 中需要这些文件

  require 'capybara/rspec'
  require 'capybara/rails'

也检查这个帖子

于 2012-05-01T10:00:52.360 回答
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
于 2012-08-09T14:32:18.747 回答