Anded 多个标签在 specflow 中无法按预期工作
Anded multiple tags do not work as expected in specflow
我的测试项目中有以下钩子:
[AfterScenario]
[Scope(Tag = "Tag1"), Scope(Tag = "Tag2")]
public static void AfterScenarioMethod()
{
}
根据 SpecFlow 文档,只有当 ScenarioContext.Current.ScenarioInfo.Tags 包含两个必需的标签时,我才应该输入 AfterFeatureMethod()。但是,即使只有 Tag1 可用,该方法也会执行。
我是不是遗漏了什么?
第一个 AfterScenario 不是静态的。
如果您在一个属性上定义多个属性,它们将使用 AND 组合。
如果您有多个属性,它们将与 OR 组合。
来自文档:https://specflow.org/documentation/Scoped-Bindings/
If multiple [Scope] attributes are defined for the same method or class, the attributes are combined with OR, i.e. at least one of the [Scope] attributes needs to match.
要检查多个标签,您必须执行以下操作:
[Binding]
public class Bindings
{
private ScenarioContext _scenarioContext;
public Bindings(ScenarioContext scenarioContext)
{
_scenarioContext = scenarioContext;
}
[AfterScenario]
public static void AfterScenarioMethod()
{
if (_scenarioContext.ScenarioInfo.Tags.Contains("Tag1") &&
_scenarioContext.ScenarioInfo.Tags.Contains("Tag2") {
//do you stuff
}
}
}
代码凭记忆写的,没试过
我的测试项目中有以下钩子:
[AfterScenario]
[Scope(Tag = "Tag1"), Scope(Tag = "Tag2")]
public static void AfterScenarioMethod()
{
}
根据 SpecFlow 文档,只有当 ScenarioContext.Current.ScenarioInfo.Tags 包含两个必需的标签时,我才应该输入 AfterFeatureMethod()。但是,即使只有 Tag1 可用,该方法也会执行。
我是不是遗漏了什么?
第一个 AfterScenario 不是静态的。
如果您在一个属性上定义多个属性,它们将使用 AND 组合。 如果您有多个属性,它们将与 OR 组合。
来自文档:https://specflow.org/documentation/Scoped-Bindings/
If multiple [Scope] attributes are defined for the same method or class, the attributes are combined with OR, i.e. at least one of the [Scope] attributes needs to match.
要检查多个标签,您必须执行以下操作:
[Binding]
public class Bindings
{
private ScenarioContext _scenarioContext;
public Bindings(ScenarioContext scenarioContext)
{
_scenarioContext = scenarioContext;
}
[AfterScenario]
public static void AfterScenarioMethod()
{
if (_scenarioContext.ScenarioInfo.Tags.Contains("Tag1") &&
_scenarioContext.ScenarioInfo.Tags.Contains("Tag2") {
//do you stuff
}
}
}
代码凭记忆写的,没试过