I just want to access the screen_shots_path parameter
from FeatureContext.php
file but writing $this->getMinkParameter('screen_shots_path');
doesn't work?
Anyone know how to do it?
Thanks in advance
I checked this one but the class extends BehatContext
and mine extends MinkContext
so I giot confused how to apply it mine.
sport/behat.yml
default:
context:
class: 'FeatureContext'
extensions:
Behat\Symfony2Extension\Extension:
mink_driver: true
kernel:
env: test
debug: true
Behat\MinkExtension\Extension:
base_url: 'http://localhost/local/sport/web/app_test.php/'
files_path: 'dummy/'
screen_shots_path: 'build/behat/'
browser_name: 'chrome'
goutte: ~
selenium2: ~
paths:
features: 'src/Football/TeamBundle/Features'
bootstrap: %behat.paths.features%/Context
sport/src/Football/TeamBundle/Features/Context/FeatureContext.php
namespace Football\TeamBundle\Features\Context;
use Behat\MinkExtension\Context\MinkContext;
use Behat\Mink\Exception\UnsupportedDriverActionException;
use Behat\Mink\Driver\Selenium2Driver;
class FeatureContext extends MinkContext
{
/**
* Take screen-shot when step fails.
* Works only with Selenium2Driver.
*
* @AfterStep
* @param $event
* @throws \Behat\Mink\Exception\UnsupportedDriverActionException
*/
public function takeScreenshotAfterFailedStep($event)
{
if (4 === $event->getResult()) {
$driver = $this->getSession()->getDriver();
if (! ($driver instanceof Selenium2Driver)) {
throw new UnsupportedDriverActionException(
'Taking screen-shots is not supported by %s, use Selenium2Driver instead.',
$driver
);
return;
}
#$directory = 'build/behat';
$directory = $this->getMinkParameter('screen_shots_path');
if (! is_dir($directory)) {
mkdir($directory, 0777, true);
}
$filename = sprintf(
'%s_%s_%s.%s',
$this->getMinkParameter('browser_name'),
date('Y-m-d') . '_' . date('H:i:s'),
uniqid('', true),
'png'
);
file_put_contents($directory . '/' . $filename, $driver->getScreenshot());
}
}
}