0

我在规范流中使用给定的代码来生成范围报告。测试执行和报告生成成功,但在范围报告中显示错误的步骤名称,并且在范围报告中替换为何时。Steps 位于 And 显示在 When 中,而在 And 部分中编写的功能文件中的步骤。

在功能文件中的 And 语法下编写的步骤,显示在 When in Extent 报告下。

我正在使用以下代码生成范围报告。

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);

            }

        }

    }
}

在此处输入图像描述

4

1 回答 1

0

问题可能是因为在 SpecFlow 中的主要关键字是 -

给定,何时,然后

可能是该报告不是从功能文件而是从代码本身进行步骤描述,我认为方法是用“ When ”关键字编写的。

于 2018-11-14T15:30:33.437 回答