在Codeception 2.1中有一个新函数current(),它有助于获得测试的当前环境:$scenario->current('env')
我使用的是1.8版,没有这样的功能。所以,我试图手动将方法current()添加到Scenario类,但它没有帮助:
protected $env = array();
protected $currents = array();
public function __construct(\Codeception\TestCase $test, $currents = array())
{
$this->test = $test;
$this->currents = $currents;
}
public function env($env)
{
if (!is_array($env)) {
$this->env[] = $env;
return;
}
foreach ($env as $e) {
$this->env($e);
}
}
public function current($key) {
if (!isset($this->currents[$key])) {
echo $this->currents[$key];
throw new TestRuntime("Current $key is not set in this scenario");
}
return $this->currents[$key];
}
答案 0 :(得分:0)
我正在使用2.1,但也许是这样的:
传递\ Codeception \ Scenario $ scenario作为第二个参数
var ev = new Event("hello");
document.dispatchEvent(ev);
我挣扎了一段时间,直到我读到这张票: https://github.com/Codeception/Codeception/issues/2225