0

Currently I am working designing my project in Specflow. I want to implement some reporting to my project. Currently I have created one separate .cs file and kept all my report setting. But these steps are getting unreachable. Can anyone please guide me how i can design my flow and how i can integrate with the feature file? Please find the below BaseReport.cs file and my Step definition file.

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

Steps

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.");
                }


            }
4

1 回答 1

0

You are missing the Binding- attribute on the BaseReport class. Without that, the hooks defined there are not called.

于 2017-05-09T09:30:59.613 回答