friends-of-behat/mink-debug-extension
Behat extension that logs Mink debug info after each failed step—ideal for CI runs. Saves page content and, with supported drivers, optional screenshots. Configurable log directory plus clean-start and screenshot options.
Installation Add the package via Composer in your Laravel project (if using Behat for testing):
composer require --dev friends-of-behat/mink-debug-extension
Configure Behat
Update your behat.yml to include the extension:
default:
extensions:
FriendsOfBehat\MinkDebugExtension:
enabled: true
First Use Case Run a failing Behat scenario. The extension will automatically:
features/debug/ (default path).behat --debug
behat --debug-clear
Debugging Failed Scenarios
Then I should see "Expected Text" → On failure, check features/debug/ for:
screenshot_*.png).dom_*.html).http_*.log).Click step fails, inspect the rendered HTML to verify element presence.Integration with Laravel
array for testing):
FriendsOfBehat\MinkDebugExtension:
session: 'laravel' # If using a custom Mink session
screenshot_dir: 'storage/logs/behat-screenshots'
When I run "php artisan migrate"):
// In a custom Mink context
$this->getSession()->executeScript('return require("fs").readFileSync("/tmp/artisan.log")');
Custom Contexts Extend the debug extension in a custom context to log additional data:
use FriendsOfBehat\MinkDebugExtension\Context\MinkDebugContext;
class CustomDebugContext extends MinkDebugContext {
public function logCustomData($data) {
$this->getMinkDebug()->log('custom', print_r($data, true));
}
}
Register in behat.yml:
contexts:
- CustomDebugContext
# behat.ci.yml
extensions:
FriendsOfBehat\MinkDebugExtension:
enabled: false
FriendsOfBehat\MinkDebugExtension:
screenshot_dir: 'storage/app/behat-screenshots'
FriendsOfBehat\MinkDebugExtension:
screenshot_filename: 'scenario_%id%_step_%step%'
Performance Overhead
enabled: false in production-like environments.Session Mismatches
$this->getSession()->reset();
File Permissions
features/debug/) must be writable.chmod -R 777 storage/logs/behat-screenshots
Headless Browsers
window.print() as a fallback:
// In a custom JS snippet
window.printToDataURL();
FriendsOfBehat\MinkDebugExtension:
proxy_log: true
git diff:
git diff features/debug/dom_*.html
$debug = $this->getMinkDebug();
$debug->setLogger(new \Monolog\Logger('behat', [
new \Monolog\Handler\StreamHandler(storage_path('logs/behat.log'))
]));
Pre/Post Hooks Add logic before/after steps:
FriendsOfBehat\MinkDebugExtension:
hooks:
before_step: ['App\Behat\DebugHooks::beforeStep']
after_step: ['App\Behat\DebugHooks::afterStep']
Custom Filters Filter debug output by step type:
// In a service provider
$extension->setFilter(function ($event) {
return $event->getStep()->getType() !== 'background';
});
Laravel Events Trigger Laravel events on debug failures:
event(new \App\Events\BehatStepFailed($step, $debugData));
How can I help you explore Laravel packages today?