PHPackages                             drupaltest/behat-traits - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. drupaltest/behat-traits

ActiveLibrary[Testing &amp; Quality](/categories/testing)

drupaltest/behat-traits
=======================

A collection of traits that help to quickly develop custom Context classes for testing Drupal sites using Behat.

0.3.0(4y ago)228.4k5[3 issues](https://github.com/drupaltest/behat-traits/issues)[2 PRs](https://github.com/drupaltest/behat-traits/pulls)1EUPL-1.2PHPPHP &gt;=7.1CI failing

Since Oct 29Pushed 2y ago4 watchersCompare

[ Source](https://github.com/drupaltest/behat-traits)[ Packagist](https://packagist.org/packages/drupaltest/behat-traits)[ RSS](/packages/drupaltest-behat-traits/feed)WikiDiscussions 8.x-1.x Synced 3w ago

READMEChangelog (2)Dependencies (11)Versions (7)Used By (1)

Behat traits
============

[](#behat-traits)

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
------------

[](#requirements)

This depends on the following software:

- [PHP 7.1](http://php.net/)
- [Drupal 8.6](https://www.drupal.org/)
- [Behat Drupal Extension](https://github.com/jhedstrom/drupalextension)

Installation
------------

[](#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
-----

[](#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
------------------------------------

[](#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

[](#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

[](#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 .

Running tests
-------------

[](#running-tests)

### Using a local LAMP stack

[](#using-a-local-lamp-stack-1)

*Coding standards*

```
$ ./vendor/bin/grumphp run
```

*Behat tests*

```
$ ./vendor/bin/behat
```

### Using Docker Compose

[](#using-docker-compose-1)

*Coding standards*

```
$ docker-compose exec web ./vendor/bin/grumphp run
```

*Behat tests*

```
$ docker-compose exec web ./vendor/bin/behat
```

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 79.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~596 days

Total

3

Last Release

1603d ago

PHP version history (2 changes)0.1.0PHP ~7.1

0.3.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/a753aefee83a2962b5962cd13c64b377eaeb1e5950e4e2ecc11f773bdebac440?d=identicon)[jhedstrom](/maintainers/jhedstrom)

![](https://avatars.githubusercontent.com/u/153362?v=4)[Antonio De Marco](/maintainers/ademarco)[@ademarco](https://github.com/ademarco)

---

Top Contributors

[![pfrenssen](https://avatars.githubusercontent.com/u/442924?v=4)](https://github.com/pfrenssen "pfrenssen (46 commits)")[![ademarco](https://avatars.githubusercontent.com/u/153362?v=4)](https://github.com/ademarco "ademarco (5 commits)")[![nagyad](https://avatars.githubusercontent.com/u/22004498?v=4)](https://github.com/nagyad "nagyad (4 commits)")[![upchuk](https://avatars.githubusercontent.com/u/5848933?v=4)](https://github.com/upchuk "upchuk (3 commits)")

### Embed Badge

![Health badge](/badges/drupaltest-behat-traits/health.svg)

```
[![Health](https://phpackages.com/badges/drupaltest-behat-traits/health.svg)](https://phpackages.com/packages/drupaltest-behat-traits)
```

###  Alternatives

[acquia/drupal-spec-tool

A tool for specifying Drupal architecture details and generating automated tests for them

1532.7M3](/packages/acquia-drupal-spec-tool)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6941.5M396](/packages/drupal-core-recommended)[drevops/behat-steps

Collection of steps for Behat

27409.9k4](/packages/drevops-behat-steps)[nuvoleweb/drupal-behat

Drupal Behat extension.

33823.5k4](/packages/nuvoleweb-drupal-behat)[mglaman/drupal-test-helpers

Helpers for writing better Kernel and Unit tests for Drupal

105.0k3](/packages/mglaman-drupal-test-helpers)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
