for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Bex\Behat\ScreenshotExtension\Service;
use Behat\Mink\Mink;
use Bex\Behat\ScreenshotExtension\Driver\ImageDriverInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* This class is responsible for taking screenshot by using the Mink session
*
* @license http://opensource.org/licenses/MIT The MIT License
*/
class ScreenshotTaker
{
/** @var Mink $mink */
private $mink;
/** @var OutputInterface $output */
private $output;
* @var array $screenshots
private $screenshots;
* Constructor
* @param Mink $mink
* @param OutputInterface $output
public function __construct(Mink $mink, OutputInterface $output)
$this->mink = $mink;
$this->output = $output;
}
* Save the screenshot as the given filename
public function takeScreenshot()
try {
$this->screenshots[] = $this->mink->getSession()->getScreenshot();
} catch (\Exception $e) {
$this->output->writeln($e->getMessage());
public function getCombinedImage()
$im = new \Imagick();
foreach ($this->screenshots as $screenshot) {
$im->readImageBlob($screenshot);
/* Append the images into one */
$im->resetIterator();
$combined = $im->appendImages(true);
/* Output the image */
$combined->setImageFormat("png");
return (string)$combined;
* Remove previous images
public function reset()
$this->screenshots = [];