2012-01-24 29 views
11

Tôi có thể nhận các phương thức capybara khác như truy cập, fill_in, chọn vv .. để hoạt động. nhưng không nhấpTại sao tôi nhận được phương pháp undefined `click 'cho Cucumber :: Rails :: World? ở Cucumber/Capybara bước

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 

lỗi:

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' 

Trả lời

1

Có lẽ bạn có nghĩa là sử dụng click_link?

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

Ngoài ra còn có click_button

Nếu không những phù hợp với nhu cầu của bạn, sau đó bạn có thể gọi click trên một phần tử.

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

Nếu không có điều nào ở trên hữu ích, thì đây là danh sách tất cả các phương pháp nhấp, nếu bạn xác định phương pháp bạn muốn sử dụng, tôi có thể hỗ trợ thêm.

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

+0

Không, tôi muốn nhấp vì có thể chọn liên kết hoặc nút. nhưng phương pháp thứ hai của bạn là gọn gàng, cảm ơn! Tôi tìm thấy câu trả lời, được đăng bên dưới. – Ivan

Các vấn đề liên quan