我有一个Behat.yml
default :
context :
parameters :
user: xyz
password : abc
我还有一个名为FeatureContext的文件.php它通过 behat.yml 检索值
public function iExample($user, $password)
{
$userName=$this->getParameter($user);
}
但它抛出一个错误,例如
"Call to undefined method FeatureContext::getParameter()"
我错过了什么吗?..我还添加了自动加载.php在FeatureContext中.php通过
require_once __DIR__.'/../../vendor/autoload.php';
请让知道,如果你有任何想法,为什么会发生这种情况?
你的FeatureContext
类必须扩展BehatContext
然后你得到参数数组作为参数在FeatureContext
的构造函数中。有关示例,请参阅 http://michaelheap.com/behat-selenium2-webdriver/。
编辑:
class FeatureContext extends BehatContext
{
private $params = array();
public function __construct(array $parameters)
{
$this->params = $parameters;
}
public function iExample($user, $password)
{
$userName = $this->params['user'];
}
}
我已经有一段时间没有使用Behat了,但你可能明白了。