Я использовал 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
мои функции / поддержка / 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, так что будьте осторожны с любыми предложениями, сказав, что ЛЮБАЯ помощь будет принята с благодарностью.