-
Add the Behat Drupal Extension to your project using Composer:
ddev composer require drupal/drupal-extension='~4.0'
` (see youtube video) This installs Behat and other required dependencies. -
Add a Selenium container in your project. Copy docker-compose.selenium.yml to your project's .ddev folder (see original source Stack Overflow answer)
-
Copy behat.yml to your project root.
-
Update
base_url
in behat.yml with your project's URL. -
Initialize Behat with
ddev exec -d /var/www/html behat --init
- This will create afeatures
folder in your project root. -
Example test: Copy account_registration.feature to the
features
directory of your project. (See youtube demonstration.) -
Run a simple test with
ddev exec -d /var/www/html behat
or
ddev ssh -d /var/www/html
behat
You should see results similar to this:
Feature: Account Registration
In order to create an account
As a user
I need to be able to complete the registration form
Scenario: Complete the registration form # features/account_registration.feature:8
Given I am on "/user/register" # Drupal\DrupalExtension\Context\MinkContext::visit()
And I enter "[email protected]" for "edit-mail" # Drupal\DrupalExtension\Context\MinkContext::assertEnterField()
And I enter "tom" for "edit-name" # Drupal\DrupalExtension\Context\MinkContext::assertEnterField()
And I press the "edit-submit" button # Drupal\DrupalExtension\Context\MinkContext::pressButton()
1 scenario (1 passed)
4 steps (4 passed)
0m0.56s (5.59Mb)
Contributed by @erubino1977