黄瓜 +水豚 + Selenium firefox 打开 example.com 不是我的应用程序

发布于 2024-11-09 08:29:07 字数 2582 浏览 3 评论 0原文

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

我的 features/support/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 相当陌生,所以请对我有任何建议,表示如有任何帮助,我们将不胜感激。

I've been using cucumber + webrat but needed extra Rails 3 compatability and javascript testing so changed to capybara + selenium. Currently I'm on Rails 3.0.7, Cucumber 0.10.2, caybara 1.0.0.beta1.

Problem: When I run a javascript scenario firefox opens "http://www.iana.org/domains/example/" or "www.example.com" instead of my rails app.

I'm sure it's just a small setting I'm missing, but I can't find it and this has had me stumped for a couple days now.

Anyway, my gemfile reads:

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

The feature is:

  @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"

The step that opens the firefox window:

    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

my features/support/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

command prompt says:

    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"'

I'm fairly new to Rails and to Ruby so be easy on me with any suggestions please, saying that ANY help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三五鸿雁 2024-11-16 08:29:07

好的,成功了。这就是我所做的。

env.rb 添加:

require "selenium-webdriver"

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

visit root_path

我认为这就是我更改的所有内容。

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

OK, got it working. Here's what I did.

env.rb added:

require "selenium-webdriver"

and changed my steps with 'visit root_url' to:

visit root_path

I think that's everything I changed.

I honestly thought I'd tried that (and every other permutation of every other issue/fix I've seen). Can't believe I've wasted 3 days on this then found the answer just hours after posting the question publicly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文