如何在 Behat FeatureContext 中获取标签
How to get tags in Behat FeatureContext
有没有办法获取 Behat FeatureContext 中方法正在 运行 中的场景的标签?
my.feature
@SPRF1
Scenario: My scenario
Given something is done
FeatureContext
class FeatureContext implements \Behat\Behat\Context\Context
{
/**
* @Then something is done
*/
public function somethingIsDone()
{
$tags = $this->getScenarioTags(); // this doesn't exist
}
}
您应该使用 BeforeScenarioScope
挂钩。
尝试这样的事情:
/**
* @BeforeScenario
*/
public function getTestId(BeforeScenarioScope $scope)
{
$tags = $scope->getScenario()->getTags();
}
别忘了加上use Behat\Behat\Hook\Scope\BeforeScenarioScope;
有没有办法获取 Behat FeatureContext 中方法正在 运行 中的场景的标签?
my.feature
@SPRF1
Scenario: My scenario
Given something is done
FeatureContext
class FeatureContext implements \Behat\Behat\Context\Context
{
/**
* @Then something is done
*/
public function somethingIsDone()
{
$tags = $this->getScenarioTags(); // this doesn't exist
}
}
您应该使用 BeforeScenarioScope
挂钩。
尝试这样的事情:
/**
* @BeforeScenario
*/
public function getTestId(BeforeScenarioScope $scope)
{
$tags = $scope->getScenario()->getTags();
}
别忘了加上use Behat\Behat\Hook\Scope\BeforeScenarioScope;