drevops / behat-screenshot
Behat extension and step definitions to create HTML and image screenshots on demand or when tests fail
Installs: 853 643
Dependents: 12
Suggesters: 0
Security: 0
Stars: 22
Watchers: 5
Forks: 8
Open Issues: 5
Requires
- php: >=8.2
- behat/behat: ^3.13.0
- friends-of-behat/mink-extension: ^2.7
- symfony/finder: ^6.4 || ^7.0
- symfony/http-client: ^6.0 || ^7.0
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.8
- behat/mink-browserkit-driver: ^2.2
- dantleech/gherkin-lint: ^0.2.3
- dealerdirect/phpcodesniffer-composer-installer: ^1
- drevops/behat-phpserver: ^1.2
- drupal/coder: ^8.3
- dvdoug/behat-code-coverage: ^5.3
- ergebnis/composer-normalize: ^2.44
- escapestudios/symfony2-coding-standard: ^3
- lullabot/mink-selenium2-driver: ^1.7
- lullabot/php-webdriver: ^2.0.4
- mikey179/vfsstream: ^1.6
- opis/closure: ^3.6
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^11
- rector/rector: ^1.0.0
- symfony/process: ^6.4 || ^7.0
This package is auto-updated.
Last update: 2025-01-18 05:30:30 UTC
README
Behat Screenshot Extension
Behat extension and step definitions to create HTML and image screenshots on demand or when tests fail.
Features
- Create a screenshot using
I save screenshot
orsave screenshot
step definition. - Create a screenshot when test fails.
- Screenshot is saved as HTML page for Goutte driver.
- Screenshot is saved as both HTML and PNG image for Selenium driver.
- Screenshot directory can be specified through environment
variable
BEHAT_SCREENSHOT_DIR
(useful for CI systems to override values inbehat.yml
). - Screenshots can be purged after every test run by setting
purge: true
( useful during test debugging) or setting environment variableBEHAT_SCREENSHOT_PURGE=1
.
Installation
composer require --dev drevops/behat-screenshot
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' fail: true fail_prefix: 'failed_' purge: false filenamePattern: '{datetime:u}.{feature_file}.feature_{step_line}.{ext}' filenamePatternFailed: '{datetime:u}.{fail_prefix}{feature_file}.feature_{step_line}.{ext}'
In your feature:
Given I am on "http://google.com" Then I save screenshot
You may optionally specify size of browser window in the screenshot step:
Then I save 1440 x 900 screenshot And I save 800 x 600 screenshot
Options
Supported tokens
Maintenance
Local development setup
Install dependencies.
composer install
Lint code
composer lint
Fix code style
composer lint-fix
Run tests
Unit tests
composer test-unit # Run unit tests.
BDD tests
We have 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 https://getscaffold.dev/ project scaffold template