我只想從FeatureContext.php
文件訪問screen_shots_path parameter
但寫入$this->getMinkParameter('screen_shots_path');
不起作用?在FeaturesContext中訪問behat.yml變量
任何人都知道該怎麼做?
在此先感謝
我檢查this one但類extends BehatContext
和礦山extends MinkContext
所以我GIOT困惑如何使用它我的。
運動/ 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
運動/ src目錄/足球/ TeamBundle /功能/語境/ 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());
}
}
}
我會嘗試它,當我回家但從我的理解是這是我應該在我的FeatureContext做什麼? :'public function __construct(array $ parameters){$ this-directory = $ this-> getMinkParameter('screen_shots_path'); }' – BentCoder 2014-09-11 10:38:22
差不多。查看更新的部分。 – 2014-09-11 10:44:11
可愛的。我今晚會檢查一下並告訴你。現在感謝。 – BentCoder 2014-09-11 10:57:52