我使用了以下代码,但扩展报告中未显示未决步骤。有没有办法在范围报告中打印未决步骤?谢谢。
代码1:
if (ScenarioContext.Current.ScenarioExecutionStatus.ToString() == "StepDefinitionPending")
{
if (stepType == "Given")
scenarioName.CreateNode<Given>(ScenarioStepContext.Current.StepInfo.Text).Skip("Step Definition Pending");
else if (stepType == "When")
scenarioName.CreateNode<When>(ScenarioStepContext.Current.StepInfo.Text).Skip("Step Definition Pending");
else if (stepType == "Then")
scenarioName.CreateNode<Then>(ScenarioStepContext.Current.StepInfo.Text).Skip("Step Definition Pending");
}
我也在下面尝试了这段代码,但出现空指针异常:
代码2:
PropertyInfo pInfo = typeof(ScenarioContext).GetProperty("TestStatus", BindingFlags.Instance | BindingFlags.NonPublic);//Getting Null value in PropertyInfo
MethodInfo getter = pInfo.GetGetMethod(nonPublic: true);
object TestResult = getter.Invoke(ScenarioContext.Current, null);
if (TestResult.ToString() == "StepDefinitionPending")
{
if (stepType == "Given")
{
scenario.CreateNode<Given>(ScenarioStepContext.Current.StepInfo.Text).Skip("Step Definition Pending");
}
else if (stepType == "When")
{
scenario.CreateNode<When>(ScenarioStepContext.Current.StepInfo.Text).Skip("Step Definition Pending");
}
else if (stepType == "Then")
{
scenario.CreateNode<Then>(ScenarioStepContext.Current.StepInfo.Text).Skip("Step Definition Pending");
}
}
答案 0 :(得分:0)
在您的Hooks类中将TestStatus
替换为ScenarioExecutionStatus
:
PropertyInfo pInfo = typeof(ScenarioContext).GetProperty("ScenarioExecutionStatus",BindingFlags.Instance |BindingFlags.NonPublic);
MethodInfo getter = pInfo.GetGetMethod(nonPublic: true);
object TestResult = getter.Invoke(ScenarioContext.Current, null);
因为,Specflow更改了类的内部。
答案 1 :(得分:0)
尝试下面的代码。
var pendingDef = ScenarioContext.Current.ScenarioExecutionStatus.ToString();
if (pendingDef == "StepDefinitionPending")
{
if (stepType == "Given")
scenario.CreateNode<Given>(ScenarioStepContext.Current.StepInfo.Text).Skip("Step Definition Pending");
else if (stepType == "When")
scenario.CreateNode<When>(ScenarioStepContext.Current.StepInfo.Text).Skip("Step Definition Pending");
else if (stepType == "Then")
scenario.CreateNode<Then>(ScenarioStepContext.Current.StepInfo.Text).Skip("Step Definition Pending");
}