Posted almost 11 years ago. Visible to the public. Linked content.

Escaping of quotation marks in Cucumber steps and step definitions


When you have a Cucumber step like

Then I should see "Did you see those \"quotation marks\" over there?"

you'll run into trouble. Cucumber won't take your escaped quotation marks.


One workaround is to write the step as regex (since there is a step taking a regex):

Then I should see /Did you see those "quotation marks" over there\?/

Keep in mind it’s a regex – escape regex characters like '?'.

When you have a Cucumber step like

Then I should fill in "query" with "\"some phrase\""

The following matcher will match any string that follows after colon and ends at the line end (and this string may include quotes):

When /^I fill in "([^"]*)" with: (.*)$/ do |field, value| pending # express the regexp above with the code you wish you had end

Using Spreewald

Or you can simply use Spreewald's Archive Multiline String in your Scenario step:

When I fill in "query" with: """ "some phrase" """

Also see How to use triple quotes inside a Cucumber docstring.

Flaky tests are tests that sometimes fail for no obvious reason. They are the plague of many end-to-end (E2E) test suites that automate the browser through tools like Capybara and Selenium.

Join our free training event and learn to fix any flaky test suite, even in large legacy applications.

Owner of this card:

Dominik Schöler
Last edit:
about 4 years ago
by Dominik Schöler
quotes, escape, cucumber, double
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Dominik Schöler to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more