Skip to main content

Form fields

DrevOps\BehatSteps\Steps\Web\FieldTrait - Source, Example, Helpers

Manipulate form fields and verify widget functionality.

  • Set field values for various input types including selects and WYSIWYG.
  • Assert field existence, state, and selected options.
  • Support for specialized widgets like color pickers and rich text editors.
  • Disable browser validation for forms with deferred execution.
  • The @disable-form-validation tag disables validation for all forms.

Skip processing with tag: @behat-steps-skip:FieldTrait

Options​

OptionTypeDefaultTagDescription
field.enabledbooleanTRUE@behat-steps-skip:FieldTraitStrip HTML5 validation from every form of a @disable-form-validation scenario.
field.add_more_button_selectorsmap[...]-CSS selectors of the add-another-item button, tried in order.
field.required_marker_selectorsmap[...]-CSS selectors that mark a field as required, tried in order.

Steps​

@Given the browser validation for the form :selector is disabled

Disable browser validation for the form for validating errors

Given the browser validation for the form "#node-article-form" is disabled
When I go to "node/add/article"
And I press "Save"
Then I should see "Title field is required"
@When I fill in the multi-value field :field with the following values:

Fill in a multi-value field widget with a list of values

When I fill in the multi-value field "Tags" with the following values:
| value |
| Drupal |
| Behat |
| Testing |
@When I fill in the color field :field with :value

Fill value for color field

When I fill in the color field "#edit-text-color" with "#3366FF"
@When I fill in the WYSIWYG field :field with :value

Set value for WYSIWYG field

When I fill in the WYSIWYG field "edit-body-0-value" with "<p>This is a <strong>formatted</strong> paragraph.</p>"
@When I unselect the option :option from the select :selector

Unselect an option from a select field

When I unselect the option "Administrator" from the select "edit-roles"
When I unselect the option "Option B" from the select "field_multi_select"
@When I clear the select :selector

Clear all selections from a select field

When I clear the select "edit-roles"
When I clear the select "field_multi_select"
@When I check the checkbox :selector

Check the checkbox

When I check the checkbox "Checkbox label"
When I check the checkbox "edit-field-terms-0-value"
@When I uncheck the checkbox :selector

Uncheck the checkbox

When I uncheck the checkbox "Checkbox label"
When I uncheck the checkbox "edit-field-terms-0-value"
@When I choose the radio button :selector

Select a radio button

When I choose the radio button "Option A"
When I choose the radio button "edit-field-choice-option-a"
@When I fill in the field :selector with :value

Fill in a field identified by CSS selector

When I fill in the field ".field--name-body textarea" with "Hello world"
When I fill in the field "#edit-field-custom-0-value" with "Test value"
@When I fill in the datetime field :label with the date :date and the time :time

Fill in datetime field with date and optionally time

When I fill in the datetime field "Event date" with the date "2024-01-15" and the time "14:30:00"
When I fill in the datetime field "Event date" with the date "2024-01-15" and the time ""
@When I fill in the date part of the datetime field :label with :date

Fill in the date part of a datetime field

When I fill in the date part of the datetime field "Event date" with "2024-01-15"
@When I fill in the time part of the datetime field :label with :time

Fill in the time part of a datetime field

When I fill in the time part of the datetime field "Event date" with "14:30:00"
@When I fill in the start datetime field :label with the date :date and the time :time

Fill in start datetime field with date and optionally time

When I fill in the start datetime field "Event period" with the date "2024-01-15" and the time "14:30:00"
When I fill in the start datetime field "Event period" with the date "2024-01-15" and the time ""
@When I fill in the end datetime field :label with the date :date and the time :time

Fill in end datetime field with date and optionally time

When I fill in the end datetime field "Event period" with the date "2024-01-20" and the time "18:00:00"
When I fill in the end datetime field "Event period" with the date "2024-01-20" and the time ""
@Then the field :field should be empty

Assert that field is empty

Then the field "Name" should be empty
@Then the field :field should not be empty

Assert that a field is not empty

Then the field "Name" should not be empty
@Then the field :field should exist

Assert that field exists on the page using id,name,label or value

Then the field "Body" should exist
Then the field "field_body" should exist
@Then the field :field should not exist

Assert that field does not exist on the page using id,name,label or value

Then the field "Body" should not exist
Then the field "field_body" should not exist
@Then the field :field should be enabled

Assert that a field is enabled

Then the field "Tags" should be enabled
@Then the field :field should be disabled

Assert that a field is disabled

Then the field "Body" should be disabled
@Then the field :field should be required

Assert that a field is marked as required

Then the field "Email" should be required
@Then the field :field should not be required

Assert that a field is not marked as required

Then the field "Nickname" should not be required
@Then the color field :field should have the value :value

Assert that a color field has a value

Then the color field "#edit-background-color" should have the value "#FF5733"
@Then the option :option within the select :selector should exist

Assert that a select has an option

Then the option "Administrator" within the select "edit-roles" should exist
@Then the option :option within the select :selector should not exist

Assert that a select does not have an option

Then the option "Guest" within the select "edit-roles" should not exist
@Then the option :option within the select :selector should be selected

Assert that a select option is selected

Then the option "Administrator" within the select "edit-roles" should be selected
@Then the option :option within the select :selector should not be selected

Assert that a select option is not selected

Then the option "Editor" within the select "edit-roles" should not be selected
@Then the radio button :selector should be selected

Assert that a radio button is selected

Then the radio button "Option A" should be selected
Then the radio button "edit-field-choice-option-a" should be selected
@Then the radio button :selector should not be selected

Assert that a radio button is not selected

Then the radio button "Option B" should not be selected
Then the radio button "edit-field-choice-option-b" should not be selected