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?
You can access the selenium send_keys method to invoke a return event like
find_field('field2').native.send_key(:enter)
A simple solution:
When /^I submit the form$/ do
page.evaluate_script("document.forms[0].submit()")
end
Worked for me with capybara-envjs. Should work with selenium as well.
I just had to solve this problem myself. In webrat I had something like this:
Then /^I submit the "([^\"]*)" form$/ do |form_id|
submit_form form_id
end
I was able to achieve the same thing with this in Capybara:
Then /^I submit the "([^\"]*)" form$/ do |form_id|
element = find_by_id(form_id)
Capybara::RackTest::Form.new(page.driver, element.native).submit :name => nil
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With