【问题标题】:Steps doesn't generate in Extent Report in specflow步骤不会在 specflow 的范围报告中生成
【发布时间】:2018-10-30 16:29:34
【问题描述】:

我正在 specflow 中生成范围报告,我已经编写了代码并且我的测试成功执行并生成了报告,但它只显示了报告中显示的功能名称没有步骤名称。 请建议我在代码中犯了什么错误。 我附上了我生成的报告的屏幕截图,当我转到报告仪表板时,它会显示那里的步骤数。

using AventStack.ExtentReports;
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 Extent_Report
{
    [Binding]
    [TestFixture]
    class Hooks
    {
        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();
            }

        }

        [BeforeScenario]
        public static void Setup()
        {
            BasePage.Intitialize();
            BasePage.Navigate();
            test = extent.CreateTest(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");

        }


        [AfterFeature()]
        public static void EndReport()
        {
            extent.Flush();

        }

    }
}

参考:

【问题讨论】:

    标签: specflow extentreports selenium-extent-report


    【解决方案1】:

    您需要使用钩子 [After step] 或 [Before step] 并添加以下内容

    test = test.info(ScenarioStepContext.Current.StepInfo.Text);

    如果需要,您还可以在其中操作并提供更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-28
      • 1970-01-01
      • 1970-01-01
      • 2018-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多