1
votes

Running the latest builds of Rails, Cucumber and Capybara I am getting stuck when Capybara needs to press a button. I have tried to eliminate all issues and have made sure that the form is generated and displayed correctly.

I am getting 2 errors: A) If I try to press the button with the correct id or text value ('commit') B) If I try and press the button with a completely incorrect id or text value ('cxxxommit')

I can reproduce these errors on both Ubuntu and Windows 7.

The errors:

Option A

And I save the Quote
    undefined method `name' for nil:NilClass (ActionView::Template::Error)
    C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/active_support/whiny_nil.rb:48:in `method_missing'

Option B

 And I save the Quote
        no button with value or id or text 'cxxxommit' found (Capybara::ElementNotFound)
        (eval):2:in `click_button'
        ./features/step_definitions/quote_steps.rb:63:in `/^I save the Quote$/'
        features\interactions\policies\quotes.feature:22:in `And I save the Quote'

Versions:

ruby 1.9.2p290 (2011-07-09) [i386-mingw32]

Rails 3.1.3

Scenario

Scenario: Create a complete manual entered quote for a client
    When I select the XXX as YYY          
     And I save the Quote
    Then I should see "Policy was successfully created"

Steps

When /^I select the (.*) as (.*)$/ do |field, value|
    select(value, :from => field)  
end
    
When /^I save the Quote$/ do 
    # debugger  
    click_button('commit')
    # ================================================
    # The next line causes the second error
    # click_button('cxxxommit')
    # ================================================
    # find_button('commit').click
end

Please note that I have read and attempted the following SO post Cucumber press button failure (Capybara::ElementNotFound)

List of gems in use

Any help or direction would be greatly appreciated.

Thanks

2
There are a couple of inconsistencies here. Your scenario is for Item, not Quote. Also, your error message says it can't find 'cxxxommit' when the step code you gave us says 'commit'. Also, you have two "options" for error messages? You haven't shown us what code leads to which error message. Please edit the question and fix these things and preferably show us a single minimal failing scenario.Mark Thomas
@MarkThomas: Thank you for the quick feedback. I have updated the question to reflect the original issue, working in different projects breaks my brain.Daniel Jacobs
What does the HTML look like? Is it an input element or javascript action?Mark Thomas
Normal submit button. <input class="create" id="commit" name="Save Quote" type="submit" value="Save Quote" />Daniel Jacobs
That's not a button- that's either a checkbox or a radio. Try either check or chose, respectively.RobertH

2 Answers

0
votes

can you tell me what is item in following code ? I guess it should be Quote

Scenario: Create a complete manual entered quote for a client
    When I select the XXX as YYY          
     And I save the Item
    Then I should see "Item was successfully created"
0
votes

You can simply write a step as

When(/^Click button with value "([^"]*)"$/) do |value|
   #click_link_or_button btn_text
   find_button(value).click
end