Is it possible to use Minitest and Capybara to test multi-step forms in Rails? All of the examples I've read online and in Stackoverflow are using Rspec. For instance, this question.
It seems like this should be something that is possible to do in Minitest though. I'm trying to test a nested form that uses the Cocoon gem and looks like this:
Before clicking the "New Option" button:
After clicking the "New Option" button:
But, my test keeps failing at this step:
click_link 'New Option'
If I add 'save_and_open_page' after click_link 'New Option'
the browser shows that field that should be revealed by click_link 'New Option'
. It works when I test it manually on my development server though. This New Option
button is generated by Cocoon with this:
<%= link_to_add_association 'New Option', f, :options %>
So that leads me to believe that it's not finding the field on the next step because javacript is not working in Capybara and Minitest. But I'm not sure.
I have Capybara.javascript_driver = :webkit
in my test_helper.rb
file, so the javascript driver should be working
Is this a problem with Minitest? Or am I doing something wrong in my test? If I view source on the page that is generated by save_and_open_page
I can see the hidden fields in the New Option
link tag. Here's what that looks like:
Based on this question, it seems like I need to do something like this:
click_link "New Option" first("input[name='product[options_attributes][new_options][name]']").set("New Option Name")
But that gives me the error:
Capybara::ExpectationNotMet: expected to find css "input[name='product[options_attributes][new_options][name]']" at least 1 time but there were no matches
It seems like there's something wrong with Minitest & Capybara testing Javascript because it seems to fail at the "New Option" link and not after that. I can't tell if it's a problem with Javascript related to Minitest and Capybara or if I'm not accessing the field properly in Minitest.
capybara-webkit
as the driver like your tags indicate (It's obsolete, equivalent to a 7 or 8 year old browser and won't run modern JS)? If so - switch to selenium with chrome so you can actually see what is happening in the browser when the test runs. – Thomas Walpolecapybara-webkit
was indeed the problem. Going to post all the changes required to get the test working. Appreciate you pointing this out. – Lee McAlilly