【问题标题】:NoMethodError running cucumber testsNoMethodError 运行黄瓜测试
【发布时间】:2013-02-05 12:05:24
【问题描述】:

每当我尝试在 rails 应用程序上运行这个黄瓜测试时,我都会失败 - “我点击”步骤定义在其他地方工作,但每次都失败! 而且我找不到任何使用过`start_with?'方法的地方

这是错误输出:

    And I click "Add a Line Item"                            # features/step_definitions/first_test_steps.rb:17
  undefined method `start_with?' for nil:NilClass (NoMethodError)
  ./features/step_definitions/first_test_steps.rb:18:in `/^I click "(.*?)"$/'
  features/create_quote.feature:19:in `And I click "Add a Line Item"'

这是我的步骤定义的代码:

When /^I click "(.*?)"$/ do |this|
 click_on(this)
end

有什么想法吗?

【问题讨论】:

    标签: ruby-on-rails testing cucumber capybara nomethoderror


    【解决方案1】:

    如果“添加订单项”是链接,则使用

    first(:link, "Add a Line Item") 
    

    如果“添加订单项”是按钮,则使用

    first(:button, "Add a Line Item")
    

    【讨论】:

    • 这是一个按钮 - 我应该在哪里使用此代码?你能告诉我为什么它目前失败了吗?
    • 将 click_on(this) 替换为 page.first(:link, "Add a Line Item").click
    • Capybara 版本 2 现在升级了一些更改,因此它失败了。您应该在 when 步骤定义中使用:-> first(:button, "#{this}")
    猜你喜欢
    • 1970-01-01
    • 2017-10-13
    • 1970-01-01
    • 2020-12-19
    • 2020-03-28
    • 2011-04-10
    • 1970-01-01
    • 1970-01-01
    • 2019-12-06
    相关资源
    最近更新 更多