访问Capybara :: InfiniteRedirectError('http://google.com')

时间:2016-06-29 08:06:41

标签: ruby-on-rails ruby selenium cucumber capybara

我的目标是使用黄瓜+水豚在显示的浏览器中运行硒(chromedriver)。

的Gemfile

self.env

功能性/支撑性/ env.rb

group :test do
  gem 'cucumber-rails'
  gem 'database_cleaner'
  gem 'selenium-webdriver'
  gem 'rspec-rails'#, '~> 3.3.2'
end

test.feature

require 'cucumber/rails'
require 'selenium-webdriver'    # Setup selenium-drivers for capybara

Capybara.register_driver :selenium_chrome do |app|
  Capybara::Selenium::Driver.new(app, :browser => :chrome)
end

Capybara.current_driver = :selenium_chrome

test_steps.rb

Feature: Google
  Scenario: When I go to google, I am supposed to be on google
  Given I am on google

当我运行黄瓜时,它会以错误结束

  

重定向超过5次,检查无限重定向。   (水豚:: InfiniteRedirectError)

它甚至没有打开浏览器......我做错了什么?

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

由于这篇文章,我修复了它:https://gist.github.com/pranav7/0f377b91a8b2cafe71bd

我需要将其放在 features / support / env.rb

require 'cucumber/rails'
require 'capybara/cucumber'

Capybara.register_driver :chrome do |app|
  client = Selenium::WebDriver::Remote::Http::Default.new
  client.timeout = 120
  Capybara::Selenium::Driver.new(app, :browser => :chrome, :http_client => client)
end

Capybara.default_driver = :chrome