Cucumber + Capybara + Selenium firefox打开example.com而不是我的应用程序

Ric*_*kyD 5 selenium cucumber capybara ruby-on-rails-3

我一直在使用黄瓜+ webrat,但需要额外的Rails 3兼容性和javascript测试,所以改为capybara + selenium.目前我在Rails 3.0.7,Cucumber 0.10.2,caybara 1.0.0.beta1.

问题:当我运行javascript场景时,firefox打开"http://www.iana.org/domains/example/"或"www.example.com"而不是我的rails应用程序.

我确定这只是一个我失踪的小设置,但是我找不到它,这让我难倒了好几天了.

无论如何,我的gemfile读取:

group :development, :test do
  gem 'cucumber'
  gem 'cucumber-rails', ">= 0.3.2"
  gem 'pickle'
  gem "launchy"
  gem "rspec-rails"
  gem "Selenium"
  gem "selenium-client"
  gem "selenium-webdriver"
  gem "database_cleaner"
  gem "factory_girl_rails"
  gem "capybara"
  gem "escape_utils"
end
Run Code Online (Sandbox Code Playgroud)

功能是:

  @wip
  @javascript
  Scenario: Calculate 1 recipe and be deducted a credit
    Given the following page records
      | name | permalink |
      | home | home      |
    And the following role records
      | name       |
      | SuperAdmin |
      | Admin      |
      | Customer   |
    When  I register "adam" with password "password"
    And I go to the index
    Then I should see "5 credits"
Run Code Online (Sandbox Code Playgroud)

打开firefox窗口的步骤:

    When /^I am logged in as "([^"]*)" with password "([^"]*)"$/ do |username, password|
  unless username.blank?
    visit(root_path)
    fill_in "user_session_username", :with => username
    fill_in "user_session_password", :with => password
    click_button "login"
    page.should have_content("Successfully logged in!")
  end
end
Run Code Online (Sandbox Code Playgroud)

我的功能/支持/ env.rb:

   require 'cucumber/rails'
    require 'factory_girl'
    require 'ruby-debug'
    require 'selenium/client'
    # require 'capybara/cucumber' commented out because it doesn't want to work with it in
    Capybara.default_driver = :selenium

    Capybara.server_boot_timeout = 50
    Capybara.default_selector = :css

    begin
      DatabaseCleaner.strategy = :truncation
    rescue NameError
      raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
    end
Run Code Online (Sandbox Code Playgroud)

命令提示符说:

    When I register "adam" with password "password"     # features/step_definiti
ons/web_steps.rb:229
      no link with title, id or text 'register' found (Capybara::ElementNotFound
)
      (eval):2:in `click_link'
      ./features/step_definitions/web_steps.rb:232:in `/^I register "([^"]*)" wi
th password "([^"]*)"$/'
      features\credit_behaviour.feature:30:in `When I register "adam" with passw
ord "password"'
Run Code Online (Sandbox Code Playgroud)

我对Rails和Ruby都很陌生,所以请提出任何建议对我很轻松,并说非常感谢任何帮助.

Ric*_*kyD 14

好的,搞定了.这就是我做的.

env.rb补充道:

require "selenium-webdriver"
Run Code Online (Sandbox Code Playgroud)

并使用'visit root_url'将我的步骤更改为:

visit root_path
Run Code Online (Sandbox Code Playgroud)

我认为这就是我改变的一切.

老实说,我以为我已经尝试过了(以及我见过的所有其他问题/解决方案的所有其他排列).不敢相信我已经浪费了3天,然后在公开发布问题几个小时后找到答案.