Another common task you are likely to want to automate is the completion and submission of forms.
Again Capybara provides a lot of user-friendly API to do just this. Consider this simple form snippet:
<form id="myform"> <input type="text" name="Forename" value="" /> <input type="text" name="Surname" value="" /> <input type="submit" value="Go" /> </form>
The following Cucumber step definition would fill in and submit the form:
When(/^I complete and submit the form$/) do fill_in 'Forename', :with => 'Matthew' fill_in 'Surname', :with => 'Robbins' click_on 'Go' end
When locating fields that can accept text input, Capybara will use one of the following to find those fields in the DOM:
idattribute of the