Cucumber cheat sheet

Cucumber cheat sheet is very hard to find. Trying to find it, you will most likely to find Capybara cheat sheet which imposes as ‘Cucumber’, but in fact those are two different things. Here I am going to list the common list of cucumber steps used in tests:

Form interaction

And I click on "Some button"
And I fill in "some_input_field_id" with "Useful content"
And I select "Something" from "dropdown_id"

Wasn’t that easy? One step that would need special definition in Capybara in order to be user as Cucumber steps is selecting a checkbox. Here is an example how it should look like:

When /^(?:|I )check "([^"]*)"$/ do |field|
find("input[type='checkbox'][value='#{field.downcase}']").set(true)
end

When /^(?:|I )uncheck "([^"]*)"$/ do |field| 
find("input[type='checkbox'][value='#{field.downcase}']").set(true)
end

In order to check if checkbox is checked:

Then /^Checkbox "([^"]*)" should be checked$/ do |checkbox|
page.has_checked_field?("#{checkbox}").should be_true
end

Then /^Checkbox "([^"]*)" should be unchecked$/ do |checkbox|
page.has_checked_field?("#{checkbox}").should be_false
end

Some additional cucumber cheat sheet steps would include confirmation of expectations:

Then I should see "My awesome cucumber test"

If you would like to submit a form via cucumber, you could write definition like this:

When /^I submit form within "(.+)"$/ do |id|
within("##{id}") do
first('input[type=submit][value=Submit]').click
end
end

This was a small list of basic cucumber cheat sheet steps. Hope you’ll find it useful.

For more reference you can refer directly with documentation https://www.relishapp.com/kucaahbe/cucumber-websteps/docs/defined-steps/forms-steps