ezsystems/behat-screenshot-image-driver-cloudinary
Install the package:
composer require --dev ezsystems/behat-screenshot-image-driver-cloudinary
Configure behat.yml:
default:
extensions:
Bex\Behat\ScreenshotExtension:
active_image_drivers: cloudinary
First Use Case:
Screenshot has been taken. Open image at https://res.cloudinary.com/your_cloud_name/...
Signed Uploads (Recommended for Production):
export CLOUDINARY_CLOUD_NAME=your_cloud_name
export CLOUDINARY_API_KEY=your_api_key
export CLOUDINARY_API_SECRET=your_api_secret
behat.yml.Unsigned Uploads (For Testing):
behat.yml with cloud_name and preset:
image_drivers:
cloudinary:
cloud_name: your_cloud_name
preset: your_preset_name
Screenshot Directory Management:
screenshot_directory: /tmp/behat-screenshots/
Limit Screenshots:
limit: 10 # Max 10 screenshots per run
export DISABLE_BEHAT_SCREENSHOT_LIMIT=true
Laravel-Specific:
.env:
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret
BehatServiceProvider or test setup:
putenv('CLOUDINARY_CLOUD_NAME=' . config('services.cloudinary.cloud_name'));
Custom Context Hooks:
use Behat\Behat\Context\Context;
use Bex\Behat\ScreenshotExtension\Context\ScreenshotContext;
class CustomScreenshotContext implements Context {
public function __construct(private ScreenshotContext $screenshotContext) {}
public function beforeScenario(\Behat\Behat\Event\BeforeScenarioScope $event) {
$this->screenshotContext->setScreenshotDirectory(sys_get_temp_dir() . '/custom_screenshots');
}
}
Environment Variables Override Config:
cloud_name, api_key, or api_secret are set as environment variables, they override behat.yml settings. Test locally with unsigned uploads first.Screenshot Directory Permissions:
screenshot_directory is writable by the web server/user running Behat:
chmod -R 777 /tmp/behat-screenshots/
/tmp in production; use a dedicated directory.Limit Quirk:
limit feature counts files in screenshot_directory. If tests run in parallel, limits may be hit unexpectedly. Clean the directory after all tests complete.Cloudinary Preset Requirements:
preset must allow uploads from your Behat server’s IP. Test with a temporary preset first.Failed Uploads:
behat --verbose
Missing Screenshots:
active_image_drivers includes cloudinary in behat.yml.Bex\Behat\ScreenshotExtension is properly loaded (check behat --version).Custom Cloudinary Options:
behat.yml (if supported by the driver):
image_drivers:
cloudinary:
transformation: "c_scale,w_800"
Post-Processing:
// In a custom context or hook
$this->screenshotContext->addScreenshotMetadata([
'context' => 'test_id_' . $event->getScenario()->getId(),
]);
Fallback Drivers:
active_image_drivers: [cloudinary, local]
How can I help you explore Laravel packages today?