I am new to the Gherkin language and this seems to me like very basic question but I could not find answer to it.
I am aware that it is possible to write multi-line step argument in Gherking, like this:
Given a blog post named "Random" with Markdown body
"""
Some Title, Eh?
==============
Here is the first paragraph of my blog post. Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
"""
My question is about writing single step on multiple lines, something like this:
Given that Gherkin language allows me to write my step definitions \
on multiple lines
Then my test cases would be easier to read :)
In the example above I used '\' as line continuation symbol. BTW, I tried the example above and got parser error.
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 :)