PHPackages                             drevops/behat-screenshot - 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. drevops/behat-screenshot

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

drevops/behat-screenshot
========================

Behat extension and step definitions to create HTML and image screenshots on demand or when tests fail

2.2.0(7mo ago)231.6M↓12.4%8[4 issues](https://github.com/drevops/behat-screenshot/issues)14GPL-2.0-or-laterPHPPHP &gt;=8.2CI passing

Since Apr 20Pushed 1mo ago4 watchersCompare

[ Source](https://github.com/drevops/behat-screenshot)[ Packagist](https://packagist.org/packages/drevops/behat-screenshot)[ GitHub Sponsors](https://github.com/drevops)[ Patreon](https://www.patreon.com/drevops)[ RSS](/packages/drevops-behat-screenshot/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (23)Versions (32)Used By (14)

  ![Behat screenshot logo](logo.png)

Behat extension to create screenshots
=====================================

[](#behat-extension-to-create-screenshots)

[![GitHub Issues](https://camo.githubusercontent.com/e0a5aeb5cadf0e3917003dec090385357b37518c6328aae0a3dfb53d289564f6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f647265766f70732f62656861742d73637265656e73686f742e737667)](https://github.com/drevops/behat-screenshot/issues)[![GitHub Pull Requests](https://camo.githubusercontent.com/90e8696ad4c6e9c6765e4e9e04e068611879a87cc6ceb037440217af2dcbd672/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d70722f647265766f70732f62656861742d73637265656e73686f742e737667)](https://github.com/drevops/behat-screenshot/pulls)[![Test](https://github.com/drevops/behat-screenshot/actions/workflows/test.yml/badge.svg)](https://github.com/drevops/behat-screenshot/actions/workflows/test.yml)[![codecov](https://camo.githubusercontent.com/489ad44e53b3a1aaf7d97c93239b1dbd20d95bc0ddf7b0f448d9d56e657a8852/68747470733a2f2f636f6465636f762e696f2f67682f647265766f70732f62656861742d73637265656e73686f742f67726170682f62616467652e7376673f746f6b656e3d554e3933305338464743)](https://codecov.io/gh/drevops/behat-screenshot)[![GitHub release (latest by date)](https://camo.githubusercontent.com/c2d1ad04f34e800175c760d610f233030dc5ef744966d026eae3a0e503d0bcf9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f647265766f70732f62656861742d73637265656e73686f74)](https://camo.githubusercontent.com/c2d1ad04f34e800175c760d610f233030dc5ef744966d026eae3a0e503d0bcf9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f647265766f70732f62656861742d73637265656e73686f74)[![LICENSE](https://camo.githubusercontent.com/711529eaf5ca8a84f721493ef35c28a2a73472f309a1d61d914f6ae46d3a3bae/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f647265766f70732f62656861742d73637265656e73686f74)](https://camo.githubusercontent.com/711529eaf5ca8a84f721493ef35c28a2a73472f309a1d61d914f6ae46d3a3bae/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f647265766f70732f62656861742d73637265656e73686f74)[![Renovate](https://camo.githubusercontent.com/35389190ce58a3690fe850342c1c3fd4f54e4c10ba8996741c8558ee24bf50dc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f72656e6f766174652d656e61626c65642d677265656e3f6c6f676f3d72656e6f76617465626f74)](https://camo.githubusercontent.com/35389190ce58a3690fe850342c1c3fd4f54e4c10ba8996741c8558ee24bf50dc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f72656e6f766174652d656e61626c65642d677265656e3f6c6f676f3d72656e6f76617465626f74)

[![Total Downloads](https://camo.githubusercontent.com/c60c714ced023b94c0432a4712d3d5c88072fb80b1a1933dba62cacb64e65da0/68747470733a2f2f706f7365722e707567782e6f72672f647265766f70732f62656861742d73637265656e73686f742f646f776e6c6f616473)](https://packagist.org/packages/drevops/behat-screenshot)

[![Vortex Ecosystem](https://camo.githubusercontent.com/08d2ce6f52424a739d03c7df3f08b096f591c5198618d51756c11b2b69bde397/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2546302539462538432538302d566f7274657825323045636f73797374656d2d3243354136383f7374796c653d666f722d7468652d6261646765266c6162656c436f6c6f723d363541434243)](https://github.com/drevops/vortex)

---

Features
--------

[](#features)

- Captures a screenshot using the `I save screenshot` step.
- Captures fullscreen screenshots with the `I save fullscreen screenshot` step.
- Automatically captures a screenshot when a test fails.
- Supports both HTML and PNG screenshots.
- Supports Selenium and Headless drivers.
- Configurable screenshot directory.
- Automatically purges screenshots after each test run.
- Adds additional information to screenshots.

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

[](#installation)

```
composer require --dev drevops/behat-screenshot
```

Usage
-----

[](#usage)

Example `behat.yml` with default parameters:

```
default:
  suites:
    default:
      contexts:
        - DrevOps\BehatScreenshotExtension\Context\ScreenshotContext
        - FeatureContext
  extensions:
    DrevOps\BehatScreenshotExtension: ~
```

or with parameters:

```
default:
  suites:
    default:
      contexts:
        - DrevOps\BehatScreenshotExtension\Context\ScreenshotContext
        - FeatureContext
  extensions:
    DrevOps\BehatScreenshotExtension:
      dir: '%paths.base%/screenshots'
      on_failed: true
      purge: false
      always_fullscreen: false
      fullscreen_algorithm: resize # Options: 'stitch' or 'resize'
      failed_prefix: 'failed_'
      filename_pattern: '{datetime:u}.{feature_file}.feature_{step_line}.{ext}'
      filename_pattern_failed: '{datetime:u}.{failed_prefix}{feature_file}.feature_{step_line}.{ext}'
```

In your feature:

```
Given I am on "http://google.com"
Then I save screenshot
```

You can capture fullscreen screenshots:

```
Given I am on "http://google.com"
Then I save fullscreen screenshot
```

There are two algorithms available for capturing fullscreen screenshots:

1. **Resize** (default): Temporarily resizes the browser window to the full height of the page to capture everything in one screenshot. This is faster, but may cause layout issues on some pages.
2. **Stitch**: Takes multiple screenshots while scrolling the page and stitches them together. This produces high-quality results with proper content rendering but requires the GD extension.

You can configure which algorithm to use via the `fullscreen_algorithm` option:

```
default:
  extensions:
    DrevOps\BehatScreenshotExtension:
      fullscreen_algorithm: resize # Options: 'stitch' or 'resize'
```

You may optionally specify the size of the browser window in the screenshot step:

```
Then I save 1440 x 900 screenshot
# Or with fullscreen
Then I save fullscreen 1440 x 900 screenshot
```

or a file name:

```
Then I save screenshot with name "my_screenshot.png"
# Or with fullscreen
Then I save fullscreen screenshot with name "my_screenshot.png"
```

To always capture fullscreen screenshots, even without explicitly using the `fullscreen` keyword, set the `always_fullscreen` configuration option to `true`:

```
default:
  extensions:
    DrevOps\BehatScreenshotExtension:
      always_fullscreen: true
```

### Capturing Screenshots After Every Step

[](#capturing-screenshots-after-every-step)

To automatically capture a screenshot after every step, you can either:

1. **Enable globally** in configuration:

```
default:
  extensions:
    DrevOps\BehatScreenshotExtension:
      on_every_step: true
```

2. **Enable per-scenario** using the `@screenshots` tag:

```
@screenshots
Scenario: My scenario with automatic screenshots
  Given I am on "http://example.com"
  When I click "Login"
  Then I should see "Welcome"
  # Screenshots will be captured after each of these steps
```

The `@screenshots` tag takes precedence over the global configuration, allowing you to enable this feature for specific scenarios even when it's disabled globally.

**Note**: When both `on_every_step` and `on_failed` are enabled, only one screenshot is captured for failed steps (the failed screenshot) to avoid duplicates.

Options
-------

[](#options)

NameDefault valueDescription`dir``%paths.base%/screenshots`Path to directory to save screenshots. Directory structure will be created if the directory does not exist. Override with `BEHAT_SCREENSHOT_DIR` env var.`on_failed``true`Capture screenshot on failed test.`on_every_step``false`Automatically capture screenshots after every step. Can be enabled globally via config or per-scenario using the `@screenshots` tag. Only captures on passed steps to avoid duplicates with `on_failed`.`purge``false`Remove all files from the screenshots directory on each test run. Useful during debugging of tests.`always_fullscreen``false`Always use fullscreen screenshot capture for all screenshot steps, including regular screenshot steps. When enabled, all `I save screenshot` steps will behave like `I save fullscreen screenshot`.`fullscreen_algorithm``resize`Algorithm to use for fullscreen screenshots. Options: `resize` (temporarily resizes browser window to full page height) or `stitch` (captures multiple screenshots while scrolling and stitches them together). The stitch algorithm requires GD extension but produces higher quality results.`info_types``url`, `feature`, `step`, `datetime`Show additional information on screenshots. Comma-separated list of `url`, `feature`, `step`, `datetime`, or remove to disable. Ordered as listed.`failed_prefix``failed_`Prefix failed screenshots with `failed_` string. Useful to distinguish failed and intended screenshots.`filename_pattern``{datetime:u}.{feature_file}.feature_{step_line}.{ext}`File name pattern for successful assertions.`filename_pattern_failed``{datetime:u}.{failed_prefix}{feature_file}.feature_{step_line}.{ext}`File name pattern for failed assertions.### File name tokens

[](#file-name-tokens)

TokenSubstituted withExample value(s)`{ext}`The extension of the file captured`html` or `png``{failed_prefix}`The value of failed\_prefix from configuration`failed_`, `error_` (do include the `_` suffix, if required)`{url}`Full URL`http_example_com_mypath_subpath_query_myquery_1_plus_2_fragment``{url_origin}`Scheme with domain`http_example_com``{url_relative}`Path + query + fragment`mypath_subpath_query_myquery_1_plus_2_fragment``{url_domain}`Domain`example_com``{url_path}`Path`mypath_subpath``{url_query}`Query`myquery_1_plus_2``{url_fragment}`Fragment`somefragment``{feature_file}`The filename of the `.feature` file currently being executed, without extension`my_example.feature` -&gt; `my_example``{step_line}`Step line number`1`, `10`, `100``{step_line:%03d}`Step line number with leading zeros. Modifiers are from `sprintf()`.`001`, `010`, `100``{step_name}`Step name without `Given/When/Then` and lower-cased.`i_am_on_the_test_page``{datetime}`Current date and time. defaults to `Ymd_His` format.`20010310_171618``{datetime:U}`Current date and time as microtime. Modifiers are from `date()`.`1697490961192498`Auto-purge
----------

[](#auto-purge)

By default, the `purge` option is disabled. This means that the screenshot directory will not be cleared after each test run. This is useful when you want to keep the screenshots for debugging purposes.

If you want to clear the directory after each test run, you can enable the `purge` option in the configuration.

```
default:
  extensions:
    DrevOps\BehatScreenshotExtension:
      purge: true
```

Alternatively, you can use `BEHAT_SCREENSHOT_PURGE` environment variable to enable the auto-purge feature for a specific test run.

```
BEHAT_SCREENSHOT_PURGE=1 vendor/bin/behat
```

Additional information on screenshots
-------------------------------------

[](#additional-information-on-screenshots)

You can enable additional information on screenshots by setting `info_types` in the configuration. The order of the types will be the order of the information displayed on the screenshot.

By default, the information displayed is the URL, feature file name, step line:

```
Current URL: http://example.com
Feature: My feature
Step: I save screenshot (line 8)
Datetime: 2025-01-19 00:01:10

>

...

```

More information can be added by setting the `info_types` configuration option and using `addInfo()` method in your context class.

```
/**
 * @BeforeScenario
 */
public function beforeScenarioUpdateBaseUrl(BeforeScenarioScope $scope): void {
  $environment = $scope->getEnvironment();
  if ($environment instanceof InitializedContextEnvironment) {
    foreach ($environment->getContexts() as $context) {
      if ($context instanceof ScreenshotContext) {
        $context->addInfo('Custom info', 'My custom info');
      }
    }
  }
}
```

Maintenance
-----------

[](#maintenance)

```
composer install
composer lint
composer lint-fix
composer test-unit
composer test-bdd
```

### BDD tests

[](#bdd-tests)

There are tests for Selenium and Headless drivers. Selenium requires a Docker container and headless requires a Chromium browser (we will make this more streamlined in the future).

```
# Start Chromium in container for Selenium-based tests.
docker run -d -p 4444:4444 -p 9222:9222 selenium/standalone-chromium

# Install Chromium with brew.
brew cask install chromedriver
# Launch Chromium with remote debugging.
/opt/homebrew/Caskroom/chromium/latest/chromium.wrapper.sh --remote-debugging-address=0.0.0.0 --remote-debugging-port=9222
```

```
composer test-bdd  # Run BDD tests.

BEHAT_CLI_DEBUG=1 composer test-bdd  # Run BDD tests with debug output.
```

---

*Repository created using  project scaffold template*

###  Health Score

64

—

FairBetter than 99% of packages

Maintenance74

Regular maintenance activity

Popularity51

Moderate usage in the ecosystem

Community30

Small or concentrated contributor base

Maturity87

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~119 days

Recently: every ~84 days

Total

27

Last Release

225d ago

Major Versions

0.8.0 → 1.0.02021-07-27

1.6.0 → 2.0.02025-01-19

### Community

Maintainers

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

---

Top Contributors

[![AlexSkrypnyk](https://avatars.githubusercontent.com/u/378794?v=4)](https://github.com/AlexSkrypnyk "AlexSkrypnyk (83 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (75 commits)")[![bladeaweb](https://avatars.githubusercontent.com/u/14051753?v=4)](https://github.com/bladeaweb "bladeaweb (9 commits)")[![tannguyen04](https://avatars.githubusercontent.com/u/2858879?v=4)](https://github.com/tannguyen04 "tannguyen04 (5 commits)")[![phil-davis](https://avatars.githubusercontent.com/u/1535615?v=4)](https://github.com/phil-davis "phil-davis (2 commits)")[![marcortola](https://avatars.githubusercontent.com/u/15958009?v=4)](https://github.com/marcortola "marcortola (1 commits)")[![richardgaunt](https://avatars.githubusercontent.com/u/57734756?v=4)](https://github.com/richardgaunt "richardgaunt (1 commits)")[![tacman](https://avatars.githubusercontent.com/u/619585?v=4)](https://github.com/tacman "tacman (1 commits)")

---

Tags

behatbehat-contextsbehat-extensionphpscreenshotsnapshotsnapshot-testing

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Type Coverage Yes

### Embed Badge

![Health badge](/badges/drevops-behat-screenshot/health.svg)

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

###  Alternatives

[drupal/drupal-extension

Drupal extension for Behat

22215.1M147](/packages/drupal-drupal-extension)[friends-of-behat/variadic-extension

Variadic support for behat context arguments

2286.0M446](/packages/friends-of-behat-variadic-extension)[magento/magento2-functional-testing-framework

Magento2 Functional Testing Framework

15511.5M30](/packages/magento-magento2-functional-testing-framework)[acquia/orca

A tool for testing a company's software packages together in the context of a realistic, functioning, best practices Drupal build

32902.4k](/packages/acquia-orca)[wp-cli/wp-cli-tests

WP-CLI testing framework

422.7M87](/packages/wp-cli-wp-cli-tests)[drevops/behat-steps

Collection of steps for Behat

25381.7k3](/packages/drevops-behat-steps)

PHPackages © 2026

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