User login

Filling in a textarea with multiple lines in a Behat test

Here's the syntax you're looking for:

    And I fill in "Team" with:
      Lost dog
      Which army
      Runaround Sue

This is possible with MinkContext::fillField(). MinkExtension is a standard part of Behat, and the fillField() method is the same one that processes steps in the form When I fill in "Fieldname" with "Value". The key is if the colon after the with is used, then the value can start on the next line, spanning multiple lines with the PyString syntax.

Here's the step definition as found with a behat -d "field" for a project using the Behat DrupalExtension:

When /^(?:|I )fill in "(?P(?:[^"]|\\")*)" with:$/
        | Fills in form field with specified id|name|label|value
        | Example: When I fill in "username" with: "bwayne"
        | Example: And I fill in "bwayne" for "username"
        | at `Drupal\DrupalExtension\Context\MinkContext::fillField()`

But as noted this is present in Behat's regular MinkExtension.

Searched words: 
behat multiline text behat multiline fields behat enter into textarea a value spanning multiple lines


Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or "class="OPTIONS" title="the title".
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.