Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get undefined method `click' for Cucumber::Rails::World ? in Cucumber / Capybara steps

I can get other capybara methods like visit, fill_in, select etc.. to work. but not click

Given /^a no fee license called "([^"]*)"$/ do |arg1|
  @l = FactoryGirl.create(:license,
                      name: arg1)
end

When /^execute the license$/ do
  visit(license_path(@l))
  click('Execute License')
end

error:

Scenario: no fee license is executed                                 # features/visitor_no_fee_license.feature:14
    When I fill out the licensee info with valid info                  # features/step_definitions/licenses_steps.rb:21
    And execute the license                                            # features/step_definitions/licenses_steps.rb:35
      undefined method `click' for #<Cucumber::Rails::World:0x007feebad4dec8> (NoMethodError)
      ./features/step_definitions/licenses_steps.rb:37:in `/^execute the license$/'
      features/visitor_no_fee_license.feature:16:in `And execute the license'
like image 673
Ivan Avatar asked Jan 24 '12 20:01

Ivan


2 Answers

Capybara's DSL changed. Use click_on instead of click, if you don't know if it's a link or a button now.

https://github.com/jnicklas/capybara/blob/549e67336c712a1ef2119ce5ff64dbbc7542480f/lib/capybara/session.rb

like image 131
Ivan Avatar answered Oct 24 '22 07:10

Ivan


Perhaps you meant to use click_link?

When /^(?:|I )follow "([^"]*)"$/ do |link|
  click_link(link)
end

There is also click_button

If neither of these suit your needs, then you can call click on an element.

When /^(?:|I )click "([^"]*)" span$/ do |selector|
  element ||= find('span', :text => selector)
  element.click
end

If none of the above is helpful, then here are a list of all the click methods, if you identify the one you wish to use, I may be able to assist further.

http://rubydoc.info/search/github/jnicklas/capybara/master?q=click

like image 42
Gazler Avatar answered Oct 24 '22 07:10

Gazler