drupaltest / behat-traits
A collection of traits that help to quickly develop custom Context classes for testing Drupal sites using Behat.
Installs: 28 184
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 5
Forks: 5
Open Issues: 5
Requires
- php: >=7.1
- drupal/core: ^8.6 || ^9
- drupal/drupal-extension: ~4.0
Requires (Dev)
- composer/installers: ~1.2
- drupal/core-composer-scaffold: ^8.9 || ^9
- drupal/core-dev: ^8.9 || ^9
- drush/drush: ~10.3
- guzzlehttp/guzzle: ~6.3
- instaclick/php-webdriver: ^1.4.5
- nikic/php-parser: ~3.0|~4.0
- openeuropa/code-review: ^1.6|^2.0
- openeuropa/task-runner-drupal-project-symlink: ^1.0.0-beta5
This package is auto-updated.
Last update: 2024-12-10 10:07:32 UTC
README
A collection of traits that help to quickly develop custom Context classes for testing Drupal sites using Behat.
The following traits are included:
BrowserCapabilityDetectionTrait
: allows to detect whether a scenario is using a browser that supports JavaScript. This can be used to write step definitions that can interact both with JavaScript behaviors and non-JS fallbacks.EntityTrait
: provides methods that allow to interact with entities using human readable names in step definitions, and translate them to machine names.PageCacheTrait
: allows to write step definitions that are aware of whether the page that is currently loaded is cached or cacheable.
Each of these traits come with an example context that include some step definitions to demonstrate how to use the traits.
Requirements
This depends on the following software:
Installation
Install the package and its dependencies. Since this is intended to be used for
testing, use the --dev
option to install it as a development dependency:
$ composer require --dev drupaltest/behat-traits
Usage
The project offers a number of traits that help to quickly create custom Behat Context classes by performing common tasks that are typically needed in step definitions for Drupal projects.
For some examples on how this can be used, see the test contexts in the
./src/Context/
folder.
Setting up a development environment
If you want to contribute to Behat Traits you can install a local development environment for it by executing the following steps:
Step 0: Clone the repository
$ git clone https://github.com/drupaltest/behat-traits.git
$ cd behat-traits
Using a local LAMP stack
Step 1: Install dependencies
$ composer install
Step 2: Configure the environment
Copy runner.yml.dist
to runner.yml
and change the configuration to match
your local environment. Typically you will need to specify localhost
as your
database host, and change your base URL and database credentials.
Step 3: Build
$ ./vendor/bin/run drupal:site-setup
This will symlink the module in the proper directory within the test environment and perform token substitution in test configuration files.
Step 4: Install
$ ./vendor/bin/run drupal:site-install
Your test site will be available at ./build
.
Using Docker Compose
Step 0: Download images
$ docker-compose up -d
Step 1: Install dependencies
$ docker-compose exec web composer install
Step 2: Configure the environment
Copy runner.yml.dist
to runner.yml
and change the configuration to match
your local environment if needed. Usually this can be skipped since the module
ships with default configuration that matches the Docker environment.
Step 3: Build
$ docker-compose exec web ./vendor/bin/run drupal:site-setup
This will symlink the module in the proper directory within the test environment and perform token substitution in test configuration files.
Step 4: Install
$ docker-compose exec web ./vendor/bin/run drupal:site-install
Your test site will be available at http://localhost:8080/build.
Running tests
Using a local LAMP stack
Coding standards
$ ./vendor/bin/grumphp run
Behat tests
$ ./vendor/bin/behat
Using Docker Compose
Coding standards
$ docker-compose exec web ./vendor/bin/grumphp run
Behat tests
$ docker-compose exec web ./vendor/bin/behat