Installation Run:
composer require friends-of-behat/mink-debug-extension
Ensure your project already has behat/behat and friends-of-behat/mink-extension installed.
Configure Behat
Add the extension to your behat.yml under the default profile:
default:
extensions:
FriendsOfBehat\MinkDebugExtension:
directory: '%paths.base%/debug-logs' # Replace with your desired path
%paths.base% to reference the directory where behat.yml is located.First Use Case
Run Behat with --strict to trigger debug logs on failures:
bin/behat --strict
directory for:
screenshot: true is configured and a supported driver is used).Debugging Failed Scenarios
MinkDebugExtension as a last-resort debugging tool when:
behat --strict and let a test fail.CI/CD Integration
behat.yml with a CI-specific directory (e.g., debug-logs/ci).- name: Upload debug logs on failure
if: failure()
uses: actions/upload-artifact@v3
with:
name: behat-debug-logs
path: debug-logs/ci
Local Development Debugging
behat.yml to include:
FriendsOfBehat\MinkDebugExtension:
directory: '%paths.base%/debug-logs'
screenshot: true # Enable screenshots
selenium2 or chrome).Behat\MinkExtension to ensure the Mink session is properly initialized before debugging.Behat\Mink\Driver\Selenium2Driver or ChromeDriver for screenshots (other drivers like Goutte may not support screenshots).Logger class (see extension source for hooks).clean_start: false in behat.yml to preserve logs across runs (useful for debugging sequences of failures).rm -rf debug-logs/*
Directory Permissions
directory is unwritable.777 permissions (or adjust ownership/group).mkdir() warnings or empty debug logs.Screenshot Limitations
selenium2, chrome). Drivers like Goutte (HTML-based) will ignore screenshot: true.behat.yml:
default:
extensions:
Behat\MinkExtension:
base_url: http://example.com
goutte: ~ # No screenshots
selenium2: ~ # Screenshots supported
Goutte for HTML debugging and switch to selenium2 for visual debugging.Log Overwrite Behavior
clean_start: true (default) deletes logs before each run, which may hide cumulative debugging data.clean_start: false temporarily to preserve logs for multi-step debugging:
FriendsOfBehat\MinkDebugExtension:
clean_start: false
Strict Mode Requirement
--strict mode.--strict in your debug commands:
bin/behat --strict --tags=@smoke
Large Log Files
input[type="hidden"]).screenshot: true sparingly for targeted debugging.Inspect the HTML Snapshots
*.html files in a browser to:
Leverage Screenshots for Visual Regression
diffimg can automate screenshot comparison:
diffimg old-screenshot.png new-screenshot.png
Debug Mink Session State
getHtml(), getTitle(), or getCurrentUrl() at the time of failure.Extend the Extension
Logger class to add metadata (e.g., test environment, timestamp).
Example hook in a custom extension:
use FriendsOfBehat\MinkDebugExtension\Logger;
class CustomLogger extends Logger {
public function log($message) {
parent::log("[ENV: " . getenv('APP_ENV') . "] " . $message);
}
}
CI-Specific Quirks
selenium2 with --headless).clean_start: true and archive logs post-failure.%paths.base% resolves to the directory containing behat.yml. Use absolute paths if needed:
directory: /var/www/project/debug-logs
./logs to prevent clutter.DebugLogs vs. debug-logs).How can I help you explore Laravel packages today?