Is it possible to write a gherkin step on multiple lines?
Yes, we can write a gherkin step on multiple lines using triple set of double quotes ("""). Gherkin recognizes the triple set of double quotes as the bounding delimiters for the multi-line string and passes it in. Whatever content you write between triple set of double quotes will be passed to your step definition as a single string.
As in my current capybara project, I have written gherkin step on multiple lines as shown below:
Scenario: Some test scenario
Given Bob is on "www.abc.com"
When Bob creates team "Test Team"
Then Bob sees message:
"""
As the Team Captain you will be responsible for paying for the team after
registration closes. You will be emailed instructions at the close of
registration.
"""
And Bob clicks "Next" button
Step definition for multi line gherkins step:
And(/^(\S*) sees message:$/) do |user, message|
page.should have_content(message)
end
In this I have used the content passed as it is. You can also split your content and use as required. For more information please refer to below mentioned link: http://asymmetrical-view.com/2011/06/02/cucumber-gherkin-and-multiline-arguments.html
Hope this helps :)