Testing / Cucumber Interview Questions
What is a Doc String in Cucumber?
A Doc String is a multi-line piece of text attached to a Gherkin step, delimited by triple quotes, used when a step needs to pass a larger block of text, like a JSON payload, an email body, or a chunk of expected output, that wouldn't read well crammed onto a single line.
When the client submits the following request: """ { "name": "Widget", "price": 9.99, "inStock": true } """
@When("the client submits the following request:") public void the_client_submits_the_following_request(String requestBody) { lastResponse = apiClient.post("/products", requestBody); }
The step definition method simply receives the doc string's content as a plain String parameter, with the exact text between the triple-quote delimiters passed through as-is (aside from stripping the leading indentation common to every line), leaving it up to the step definition to parse or otherwise interpret that content.
More Related questions...