bex/behat-screenshot
最新稳定版本:2.1.0
Composer 安装命令:
composer require bex/behat-screenshot
包简介
Extension for behat to help debug failing scenarios
关键字:
README 文档
README
Behat-ScreenshotExtension helps you debug Behat scenarios by taking screenshot of the failing steps.
By default the extension takes the screenshot and save it to the preconfigured directory (by default it will save the image to the default temporary system directory).
Also the extension allows you to specify an image driver which can upload the image to a host, in this case you will see the image url in the terminal right after the failing step. See available image drivers below.
You can also create your own image driver easily, for more information see this section.
Installation
Install by adding to your composer.json:
composer require --dev bex/behat-screenshot
Configuration
Enable the extension in behat.yml like this:
default: extensions: Bex\Behat\ScreenshotExtension: ~
You can configure the screenshot directory like this:
default: extensions: Bex\Behat\ScreenshotExtension: image_drivers: local: screenshot_directory: /your/desired/path/for/screenshots clear_screenshot_directory: true # Enable removing all images before each test run. It is false by default.
If you are using another image driver you can enable it like this:
default: extensions: Bex\Behat\ScreenshotExtension: active_image_drivers: customdriver image_drivers: # this node and the driver subnodes are optional, if you remove it then the driver's default values will be used customdriver: #... custom driver config goes here ...
You can even enable more than one image driver at once:
default: extensions: Bex\Behat\ScreenshotExtension: active_image_drivers: [local, customdriver] image_drivers: local: #... local driver config goes here ... customdriver: #... custom driver config goes here ...
You can make a combined screenshot including previous steps:
default: extensions: Bex\Behat\ScreenshotExtension: screenshot_taking_mode: failed_scenarios # Available modes: # - failed_steps: Image contains only the screenshot of the failed step. [Default] # - failed_scenarios: Image contains screenshots of all steps in a failed scenario. # - all_scenarios: Each scenario has a combined image created, regardless of failing or passing.
You can disable the extension by removing from the behat.yml or you can disable it for a profile by using the enabled parameter, e.g.:
ci: extensions: Bex\Behat\ScreenshotExtension: enabled: false
Usage
When you run behat and a step fails then the extension will automatically take the screenshot and you will see the filepath or the image URL of the screenshot (based on the configured image driver). So you will see something like this:
Scenario: # features/feature.feature:2 Given I have a step # FeatureContext::passingStep() When I have a failing step # FeatureContext::failingStep() Error (Exception) Screenshot has been taken. Open image at /tmp/behat-screenshot/i_have_a_failing_step.png Then I should have a skipped step # FeatureContext::skippedStep()
Available Image Drivers
- bex/behat-screenshot-image-driver-uploadpie
- bex/behat-screenshot-image-driver-img42
- bex/behat-screenshot-image-driver-unsee
How to create your own image driver
- Implement the
Bex\Behat\ScreenshotExtension\Driver\ImageDriverInterface - Put your class under the
Bex\Behat\ScreenshotExtension\Drivernamespace
That's it!
See example here: https://github.com/tkotosz/behat-screenshot-image-driver-dummy
bex/behat-screenshot 适用场景与选型建议
bex/behat-screenshot 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.23M 次下载、GitHub Stars 达 92, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「BDD」 「Behat」 「TDD」 「behat-screenshot」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bex/behat-screenshot 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bex/behat-screenshot 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bex/behat-screenshot 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Helper that decorates any SUS with a phpspec lazy object wrapper
Behat Context for testing Symfony Api
A Behat Extension that allows custom bootstrapping
Environment processor and contexts autoloader
Provides access to magento2 object manager from behat and allows to change magento config settings temporarly
log the behat execution into json result
统计信息
- 总下载量: 5.23M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 94
- 点击次数: 32
- 依赖项目数: 34
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04