I have a test using Cucumber, capybara and selenium driver. This test should go to a form and submit it. The normal text would be
Scenario: Fill form
Given I am on the Form page
When I fill in "field1" with "value1"
And I fill in "field2" with "value2"
And I press "OK"
Then I should see "Form submited"
The problem is that I don't have the OK button in the form I need a way to do the "form.submit", without clicking any button or link - the same as happens when you press ENTER when you are in a form field using the browser.
I don't know how to tell capybara to submit a form. How can I do it?
With the capybara Selenium driver you can do something like this:
You can access the selenium send_keys method to invoke a return event like
This is a bit hackish, but it filled a need. I monkey-patched Capybara to support a
#submit
method on elements.It is not robust because it naively creates the POST parameters from every input elements's
name
andvalue
attributes. (In my case, all my<input>
elements were of typehidden
, so it works fine).You can try sending a newline:
The display:none solution does not work with capybara using selenium driver because selenium complains about interacting with invisible elements. If you try the above solution you may end up seeing the following error message:
You may probably roll your own step (And I submit the form with the link "Ok", for example), and emulate the submit functionality yourself.
Here it is the javascript emulation dropped in Rails 3 to support "unobtrusive" (emphasis on the quotes) Javascript. The line
is probably the clue to answer your problem. The full code is here