bex/behat-screenshot-image-driver-dummy
Install the Package
Add to your composer.json under require-dev:
composer require --dev bex/behat-screenshot-image-driver-dummy
Configure behat.yml
Enable the dummy driver in the Bex\Behat\ScreenshotExtension config:
default:
extensions:
Bex\Behat\ScreenshotExtension:
active_image_drivers: dummy
First Use Case
Run a failing Behat scenario. The extension will generate a dummy image URL (e.g., http://docs.behat.org/en/v2.5/_static/img/logo.png) instead of saving an actual screenshot. Useful for:
imagick/gd).Replace Real Drivers for Testing
Use the dummy driver in behat.yml for environments where screenshots aren’t required (e.g., unit tests, CI):
# behat.yml (test environment)
extensions:
Bex\Behat\ScreenshotExtension:
active_image_drivers: dummy
screenshot_directory: null # Disable saving files
Conditional Driver Switching Dynamically enable/disable the dummy driver via environment variables or PHP config:
// In a custom Behat extension or bootstrap
if (app()->environment('testing')) {
$config['extensions']['Bex\Behat\ScreenshotExtension']['active_image_drivers'] = ['dummy'];
}
Extend for Custom Dummy Logic Override the dummy URL or behavior by creating a custom driver (see Gotchas for extension points).
Service Provider Integration Bind the dummy driver to Laravel’s container for dynamic configuration:
// app/Providers/BehatServiceProvider.php
public function register()
{
$this->app->singleton('behat.screenshot.driver.dummy', function () {
return new \Bex\Behat\Screenshot\ImageDriver\DummyDriver();
});
}
Artisan Command Hooks Use the dummy driver in custom Artisan commands to simulate screenshot failures:
// app/Console/Commands/TestBehatScreenshot.php
public function handle()
{
$this->call('behat', [
'--config' => 'behat-dummy.yml', // Uses dummy driver
]);
}
Outdated Dependencies
bex/behat-screenshot (likely v1.x). Ensure compatibility with your Behat version (v3.x+ may require adjustments).Bex\Behat\ScreenshotExtension namespace if needed.No Real Screenshot Logic
// app/Behat/DummyDriver.php
namespace App\Behat;
use Bex\Behat\Screenshot\ImageDriver\DummyDriver as BaseDummyDriver;
class DummyDriver extends BaseDummyDriver
{
public function getImageUrl()
{
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...';
}
}
behat.yml:
active_image_drivers: ['App\Behat\DummyDriver']
CI/CD False Positives
expectOutput() in PHPUnit to ignore it:
$this->expectOutputToContain('Screenshot has been taken');
Verify Driver Activation Check if the driver is loaded by inspecting Behat’s output. If the URL doesn’t change, the driver isn’t active.
FeatureContext:
use Bex\Behat\ScreenshotExtension\ScreenshotExtension;
public function __construct() {
$this->getModule(ScreenshotExtension::class)->getImageDriver();
}
Log Driver Calls Extend the driver to log invocations:
class DebugDummyDriver extends BaseDummyDriver {
public function getImageUrl() {
\Log::debug('Dummy driver called!');
return parent::getImageUrl();
}
}
Custom Dummy URLs
Override getImageUrl() in a child class to return dynamic URLs (e.g., from a Laravel view):
public function getImageUrl()
{
return route('behat.dummy.image');
}
Mock File System
Combine with Laravel’s Storage facade to simulate screenshot paths:
public function saveScreenshot($image, $path)
{
Storage::disk('local')->put($path, $image);
return 'storage/' . $path; // Return a fake path
}
Integration with Laravel Testing
Use in phpunit.xml to skip screenshot steps in tests:
<env name="BEHAT_SCREENSHOT_DRIVER" value="dummy"/>
How can I help you explore Laravel packages today?