Ruby on rails 为什么我会得到未定义的方法“click';对于Cucumber::Rails::World?黄瓜/水豚步骤
我可以得到其他水豚方法,如访问、填写、选择等。。工作。但不是单击Ruby on rails 为什么我会得到未定义的方法“click';对于Cucumber::Rails::World?黄瓜/水豚步骤,ruby-on-rails,cucumber,capybara,Ruby On Rails,Cucumber,Capybara,我可以得到其他水豚方法,如访问、填写、选择等。。工作。但不是单击 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
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
错误:
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'
场景:无费用许可证被执行#功能/访客_无费用许可证。功能:14
当我用有效信息#功能/步骤#定义/许可证#步骤填写被许可人信息时。rb:21
并执行许可证#功能/step_定义/licenses_步骤。rb:35
#的未定义方法“单击”(命名错误)
./features/step\u definitions/licenses\u steps.rb:37:in`/^execute the license$/'
功能/访客\u无费用\u许可证。功能:16:in“并执行许可证”
也许你想用
还有
如果这两个都不适合您的需要,那么您可以调用一个元素
When /^(?:|I )click "([^"]*)" span$/ do |selector|
element ||= find('span', :text => selector)
element.click
end
如果以上所有方法都没有帮助,那么下面是所有单击方法的列表,如果您确定了希望使用的方法,我可以进一步提供帮助
水豚的DSL改变了。如果您现在不知道它是链接还是按钮,请使用
单击
而不是单击
不,我想要单击,因为它可以选择链接或按钮。但是你的第二种方法很好,谢谢!我找到了答案,贴在下面。
When /^(?:|I )click "([^"]*)" span$/ do |selector|
element ||= find('span', :text => selector)
element.click
end