← Back to libraryQuestion 257 of 468
🥒Cucumber / BDDBeginner

Doc Strings

📌 Definition:

A Doc String passes a large, multi-line block of text (like a JSON payload, an email body, or a message) to a single step, delimited by triple quotes in the feature file.

📖 Detailed Explanation:

When a step needs more than a short phrase — an expected JSON response, a long comment, an HTML snippet — you attach a Doc String using triple double-quotes (""") on the lines after the step. The step definition receives it as a String parameter. This keeps big text out of the step sentence and preserves formatting/whitespace. Doc Strings pair well with API scenarios (posting or asserting a JSON body). You can optionally give a content type after the opening delimiter. Use them when the data is genuinely large; for a few values a DataTable or inline parameters is clearer.

🔑 Key Points:
  • Triple-quote (""") multi-line text passed to one step
  • Received as a String argument in the step definition
  • Great for JSON payloads / long messages (preserves formatting)
  • Optional content type after the opening delimiter
🌍 Real-World Example:

When the API receives the request:\n """\n { "name": "QA", "active": true }\n """\n— the JSON body is passed as a string to the step that POSTs it.

🎯 Scenario-Based Interview Question:

You need to pass a full JSON request body to a Cucumber step. DataTable or Doc String, and why?