如何在Specflow Project中生成报告(Extent Report)

How to generate report (Extent Report) in Specflow Project

目前我正在使用 Specflow 设计我的项目。我想对我的项目实施一些报告。目前我已经创建了一个单独的 .cs 文件并保留了我所有的报告设置。但这些步骤越来越遥不可及。谁能指导我如何设计流程以及如何与功能文件集成? 请找到下面的 BaseReport.cs 文件和我的步骤定义文件。

namespace Verivox.CommonLib
{

    public class BaseReport
    {
        public static ExtentReports extent;
        public static ExtentTest test;

        [BeforeFeature()]
        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;

            string reportPath = projectPath + "Reports\" + FeatureContext.Current.FeatureInfo.Title + ".html";

            extent = new ExtentReports(reportPath, true);

            extent.LoadConfig(projectPath + "CommonLib\Extent-config.xml");

        }

        [BeforeScenario()]
        public static void BeforeScenarioSetUp()
        {

            test = extent.StartTest("Running Scenario -->" + ScenarioContext.Current.ScenarioInfo.Title);
        }

        [AfterScenario()]
        public static void AfterScnario()
        {
            if (ScenarioContext.Current.TestError != null)
            {
                var error = ScenarioContext.Current.TestError;
                var errormessage = "<pre>" + error.Message + "</pre>";
                //Add capture screen shot line here

                extent.EndTest(test);

            }
        }

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

步骤

namespace Verivox.Steps
    {
        [Binding]
        class CalculationVerificationSteps
        {
            [Given(@"I have navigate to Home Page")]
            public void GivenIHaveNavigateToHomePage()
            {
                Browser.Current.Navigate().GoToUrl(ConfigurationManager.AppSettings["seleniumBaseUrl"]);
                PropertyCollection.currentPage = new HomePage();
                Browser.Current.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));

            }

            [Given(@"Navigate to Mobile Calculator  under All Comparison Section")]
            public void GivenNavigateToMobileCalculatorUnderAllComparisonSection()
            {

                PropertyCollection.currentPage.As<HomePage>().MainCompItemClick("Telekommunikation");
                PropertyCollection.currentPage.As<HomePage>().SubCompItemClick("Mobilfunk");
                PropertyCollection.currentPage.As<HomePage>().CalculatorLinkClick("Mobiles Internet");

            }

            [Then(@"Mobile Calculator should appear")]
            public void ThenMobileCalculatorShouldAppear()
            {
                Assert.IsTrue(PropertyCollection.currentPage.As<HomePage>().IsMobileInternetCalcExistance());
            }

            [Then(@"(.*) option and (.*) option is selected by default\.")]
            public void ThenMonatsflatrateOptionAndSIMOptionIsSelectedByDefault_(string defaultTarif, string hardware)
            {
                try
                {
                    Assert.IsTrue(PropertyCollection.currentPage.As<HomePage>().VerifyMobiIntSelectedItem(defaultTarif));
                    string colorCode = PropertyCollection.currentPage.As<HomePage>().VerifySelectedHardWare();
                    Assert.AreEqual(0, string.Compare("rgba(253, 138, 2, 1)", colorCode, StringComparison.OrdinalIgnoreCase));
                }
                catch (Exception)
                {
                    BaseReport.test.Log(LogStatus.Fail, "Default selections are incorrect.");
                }


            }

您缺少 BaseReport 上的 Binding- 属性 class。没有它,那里定义的钩子就不会被调用。