ruby-on-rails-3 - Cucumber + Capybara + Selenium firefox 打开 example.com 而不是我的应用

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

我一直在使用cucumber + 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

特点是:
  @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"

打开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

我的功能/支持/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

命令提示符说:
    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"'

我对 Rails 和 Ruby 还很陌生,所以请对我提出任何建议,请不要吝啬,说任何帮助都将不胜感激。

最佳答案

好的,开始工作了。这就是我所做的。

env.rb 补充说:

require "selenium-webdriver"

并将“访问 root_url”的步骤更改为:
visit root_path

我想这就是我改变的一切。

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

关于ruby-on-rails-3 - Cucumber + Capybara + Selenium firefox 打开 example.com 而不是我的应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6124921/

相关文章:

Python Selenium + Datepicker 点击

java - 基于内部子属性的 webDriver cssSelector

ruby - 在Rails 3.x 中,如何为引用父资源的嵌套资源设计 View ?

ruby-on-rails - % 在下面的代码中做了什么?

javascript - Protractor by.repeater 找不到任何东西

ruby-on-rails - Cucumber/Webrat 未遵循 redirect_to

rspec - capybara 希望页面内容不止一次

ruby-on-rails - 如何使用 mongoid 构建管理 UI?

ruby-on-rails - 从 Rails 导出 CSV 数据

scala - 在 Cucumber 步骤定义之间传递变量