Ruby on rails 3 黄瓜+;水豚+;Selenium firefox打开example.com而不是我的应用程序
我一直在使用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应用程序 我肯定这只是我错过的一个小场景,但我找不到它,这让我困惑了好几天 无论如何,我的文件如下:Ruby on rails 3 黄瓜+;水豚+;Selenium firefox打开example.com而不是我的应用程序,ruby-on-rails-3,selenium,cucumber,capybara,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应用程序 我肯定这只是我错过的一个小场景,但我找不
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
我的功能/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都是新手,所以请您给我一些建议,如果有任何帮助,我将不胜感激。好的,开始工作了。这就是我所做的 增加了env.rb:
require "selenium-webdriver"
并使用“访问根目录url”将我的步骤更改为:
visit root_path
我想这就是我改变的一切
老实说,我认为我已经尝试过了(以及我所见过的其他问题/修复的所有其他排列)。真不敢相信我在这上面浪费了3天时间,然后在公开发布问题几个小时后就找到了答案。这是否意味着你在每次测试中都使用“路径”而不是“url”?或者你有没有找到更好的方法(可能是调整主机或其他什么?)是的,我使用的是路径而不是url。我不确定这是否是一种“正确”的方式,但它目前仍然有效。根据jnicklas,您需要确保您使用的是路径,而不是url,因为它可能会产生意想不到的后果。