范围报告中显示错误的步骤名称,并替换为“时”

问题描述 投票:0回答:1

我在规范流程中使用给定的代码来生成范围报告。测试执行和报告生成成功,但在范围报告中显示错误的步骤名称,并在范围报告中替换为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);

            }

        }

    }
}

enter image description here

specflow extentreports selenium-extent-report
1个回答
0
投票

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

鉴于,何时,然后

可能是这个报告的步骤描述不是来自Features文件,而是来自代码本身,我认为这些方法是用“When”关键字编写的。

© www.soinside.com 2019 - 2024. All rights reserved.