In Cucumber, Doc Strings are used to pass a large block of text to a step definition. This is useful when sending descriptions, JSON/XML payloads, multi-line messages, etc.
Syntax
A Doc String is enclosed within triple double quotes """ or triple backticks ```````. It must appear on the line immediately after the step.
Example 1:
Example 2:
And Send an email to the user
Step Definition for Doc String
The text in the Doc String will automatically be passed as the last argument to the step definition.
You Can Use It to Pass JSON or XML Too
JSON Payload:
XML Payload:
When to Use Doc String?
When a step needs a multi-line message or payload
To pass formatted data like JSON, XML, HTML
For email bodies, API requests, descriptions, or logs