DocStrings
Gherkin doc strings (triple-quoted blocks) become a trailing String parameter on the step method, with formatting preserved via Java text blocks.
Source: examples/common-use-cases/example-5 on GitHub.
What this demonstrates
- Doc strings become a trailing
Stringparameter on the step method - Method naming is unaffected by the doc string (no extra
$pplaceholder) - Formatting (newlines, indentation) is preserved via Java text blocks
- Doc strings can be combined with quoted parameters in the same step
- Content can be anything: JSON, plain text, XML, …
Doc string only
When I submit the following shipping address:
"""
{
"line1": "Baker St 221B",
"city": "London"
}
"""
// Step method — one String parameter for the doc string
void iSubmitTheFollowingShippingAddress(String docString);
// Generated call site — Java text block preserves formatting
iSubmitTheFollowingShippingAddress("""
{
"line1": "Baker St 221B",
"city": "London"
}
""");
Quoted args + doc string
When I add item "Wireless Headphones" with options:
"""
{ "color": "Black" }
"""
// Quoted args come first, doc string is appended after
void iAddItem$p1WithOptions(String p1, String docString);
iAddItem$p1WithOptions("Wireless Headphones", """
{ "color": "Black" }
""");
Run it
cd examples/common-use-cases/example-5
mvn test