src/LinusShops/Contexts/Web.php
public function takeScreenshotAfterFailedStep(AfterStepScope $event)
    {
        if (!$event->getTestResult()->isPassed()) {
            if ($this->getSession()->getDriver() instanceof Selenium2Driver) {
                $stepLine = $event->getStep()->getLine();
                $time = time();
                $fileName = "./step-{$stepLine}-{$time}.png";
                if (is_writable('.')) {
                    $screenshot = $this->getSession()->getDriver()->getScreenshot();
                    $stepText = $event->getStep()->getText();
                    if (file_put_contents($fileName, $screenshot)) {
                        echo "Screenshot for '{$stepText}' placed in {$fileName}".PHP_EOL;
                    } else {
                        echo "Screenshot failed: {$fileName} is not writable.";
                    }
                }
            }
        }
    }
public function takeScreenshotAfterFailedStep(AfterStepScope $event)
    {
        if (!$event->getTestResult()->isPassed()) {
            if ($this->getSession()->getDriver() instanceof Selenium2Driver) {
                $stepLine = $event->getStep()->getLine();
                $time = time();
                $fileName = "./step-{$stepLine}-{$time}.png";
                if (is_writable('.')) {
                    $screenshot = $this->getSession()->getDriver()->getScreenshot();
                    $stepText = $event->getStep()->getText();
                    if (file_put_contents($fileName, $screenshot)) {
                        echo "Screenshot for '{$stepText}' placed in {$fileName}".PHP_EOL;
                    } else {
                        echo "Screenshot failed: {$fileName} is not writable.";
                    }
                }
            }
        }
    }
public function takeScreenshotAfterFailedStep ( AfterStepScope $ event ) { if ( ! $ event -> getTestResult ( ) -> isPassed ( ) ) { if ( $ this -> getSession ( ) -> getDriver ( ) instanceof Selenium2Driver ) { $ stepLine = $ event -> getStep ( ) -> getLine ( ) ; $ time = time ( ) ; $ fileName = "./step-{$stepLine}-{$time}.png" ; if ( is_writable ( '.' ) ) { $ screenshot = $ this -> getSession ( ) -> getDriver ( ) -> getScreenshot ( ) ; $ stepText = $ event -> getStep ( ) -> getText ( ) ; if ( file_put_contents ( $ fileName , $ screenshot ) ) { echo "Screenshot for '{$stepText}' placed in {$fileName}" . PHP_EOL ; } else { echo "Screenshot failed: {$fileName} is not writable." ; } } } } }
If using the Selenium2Driver, will automatically screenshot any failed
steps and save them in the current directory.

Screenshots are named as "step-<step-line-number>-<timestamp>.png".

@AfterStep
@param AfterStepScope $event
If using the Selenium2Driver will automatically screenshot any failed steps and save them in the current directory .