我正在规格流程中使用给定的代码来生成范围报告。测试执行并成功生成报告,但在扩展区报告中显示错误的步骤名称,并在扩展区报告中替换为When。步骤位于功能文件中的“何时”下,并显示在“功能”文件中的“与”部分中。
在功能文件中的“和”语法下编写的步骤,在“在范围内”报告中的“时间”下显示。
我正在使用以下代码来生成范围报告。
using AventStack.ExtentReports;
using AventStack.ExtentReports.Gherkin.Model;
using AventStack.ExtentReports.Reporter;
using AventStack.ExtentReports.Reporter.Configuration;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TechTalk.SpecFlow;
namespace ALD_Belgium
{
[Binding]
[TestFixture]
class Hooks
{
public static ExtentTest featureName;
public static ExtentReports extent;
public static ExtentHtmlReporter htmlReporter;
public static ExtentTest test;
// public static object Theme { get; private set; }
static Hooks()
{
if (extent == null)
{
BasicSetUp();
}
}
[BeforeFeature]
public static void BeforeFeature()
{
featureName = extent.CreateTest<Feature>(FeatureContext.Current.FeatureInfo.Title);
}
[BeforeScenario]
public static void Setup()
{
BasePage.Intitialize();
BasePage.Navigate();
// test = extent.CreateTest(ScenarioContext.Current.ScenarioInfo.Title);
test = featureName.CreateNode<Scenario>(ScenarioContext.Current.ScenarioInfo.Title);
}
[AfterScenario]
public void TearDown()
{
if (ScenarioContext.Current.TestError != null)
{
var error = ScenarioContext.Current.TestError;
var errormessage = "<pre>" + error.Message + "</pre>";
extent.AddTestRunnerLogs(errormessage);
test.Log(Status.Error, errormessage);
test.Fail(errormessage);
}
BasePage.Quit();
}
[OneTimeSetUp]
public static void BasicSetUp()
{
string pth = System.Reflection.Assembly.GetCallingAssembly().CodeBase;
// string pth = System.IO.Directory.GetCurrentDirectory();
string actualPath = pth.Substring(0, pth.LastIndexOf("bin"));
string projectPath = new Uri(actualPath).LocalPath;
Console.WriteLine(" -----------Project Path--------------------------------------");
Console.WriteLine(projectPath);
string reportPath = projectPath + "Reports\\TestExecutionRunReport.html";
// Console.WriteLine("Report Path is " + reportPath);
htmlReporter = new ExtentHtmlReporter(reportPath);
htmlReporter.Configuration().Theme = Theme.Dark;
htmlReporter.Configuration().DocumentTitle = "SpecFlow Test Resport Document";
htmlReporter.Configuration().ReportName = "Feature Run Results";
extent = new ExtentReports();
extent.AttachReporter(htmlReporter);
//extent.LoadConfig(projectPath + "Extent-Config.xml");
}
[AfterTestRun]
public static void EndReport()
{
extent.Flush();
}
[AfterStep]
public static void InsertReportingSteps()
{
var stepType = ScenarioStepContext.Current.StepInfo.StepDefinitionType.ToString();
if (ScenarioContext.Current.TestError == null)
{
if (stepType == "Given")
test.CreateNode<Given>(ScenarioStepContext.Current.StepInfo.Text);
else if (stepType == "When")
test.CreateNode<When>(ScenarioStepContext.Current.StepInfo.Text);
else if (stepType == "And")
test.CreateNode<And>(ScenarioStepContext.Current.StepInfo.Text);
else if (stepType == "Then")
test.CreateNode<Then>(ScenarioStepContext.Current.StepInfo.Text);
}
else if (ScenarioContext.Current.TestError != null)
{
if (stepType == "Given")
test.CreateNode<Given>(ScenarioStepContext.Current.StepInfo.Text).Fail(ScenarioContext.Current.TestError.Message);
else if (stepType == "When")
test.CreateNode<When>(ScenarioStepContext.Current.StepInfo.Text).Fail(ScenarioContext.Current.TestError.Message);
else if (stepType == "And")
test.CreateNode<And>(ScenarioStepContext.Current.StepInfo.Text).Fail(ScenarioContext.Current.TestError.Message);
else if (stepType == "Then")
test.CreateNode<Then>(ScenarioStepContext.Current.StepInfo.Text).Fail(ScenarioContext.Current.TestError.Message);
}
}
}
}
答案 0 :(得分:0)
问题可能是因为在SpecFlow中,主要关键字是-
给出,何时,然后
该报告可能不是从功能文件而是从代码本身进行步骤描述的,我认为方法是用“ 何时”关键字编写的。