extent-framework / extentreports-csharp

Extent Reporting Library, .NET
http://extentreports.com
Apache License 2.0
50 stars 40 forks source link

Number of features is equal to number of scenarios #54

Closed ParagRaut closed 5 years ago

ParagRaut commented 5 years ago

I have multiple Features which have multiple number of scenario in each of them. In reports I see # of Feature is equal to # of Scenarios which I know is wrong. Below is screenshot: image

I'm using BDD approach and these methods to create nodes:

case "Given":
                        ScenarioName.CreateNode<Given>(stepName);
                        break;
                    case "When":
                        ScenarioName.CreateNode<When>(stepName);
                        break;
                    case "Then":
                        ScenarioName.CreateNode<Then>(stepName);
                        break;
                    case "And":
                        ScenarioName.CreateNode<And>(stepName);
                        break;

Can you tell me if I'm doing something wrong ?

rudreshtrivedi commented 5 years ago
    private static ExtentTest featureName;
    private static ExtentTest scenario;
   [BeforeFeature]
    public static void BeforeFeature()
    {
        featureName = extent.CreateTest<Feature>(FeatureContext.Current.FeatureInfo.Title);
    }
   [AfterStep]
    public void InsertReportingSteps()
    {
        try
        {
            var stepType = ScenarioStepContext.Current.StepInfo.StepDefinitionType.ToString();

            if (ScenarioContext.Current.TestError == null)
            {
                if (stepType == "Given")
                    scenario.CreateNode<Given>(ScenarioStepContext.Current.StepInfo.Text);
                else if (stepType == "When")
                    scenario.CreateNode<When>(ScenarioStepContext.Current.StepInfo.Text);
                else if (stepType == "Then")
                    scenario.CreateNode<Then>(ScenarioStepContext.Current.StepInfo.Text);
                else if (stepType == "And")
                    scenario.CreateNode<And>(ScenarioStepContext.Current.StepInfo.Text);
            }

See above example! are you using correct annotation and Feature/Scenario terminology?

ParagRaut commented 5 years ago

@rudreshtrivedi in above example you're not initializing scenario, i.e. private static ExtentTest scenario;

I use following before initializing the test,

FeatureName = ExtentReports.CreateTest(FeatureContext.Current.FeatureInfo.Title); ScenarioName = FeatureName.CreateNode(ScenarioContext.Current.ScenarioInfo.Title);

One thing I noticed is I put both statement in before scenario tag, which I can correct now

ParagRaut commented 5 years ago

Thanks it solved my issue now I do this:

[BeforeFeature]
        protected static void InitializeCurrentFeatureContext()
        {
            if (IsExtentReportsEnabled)
            {
                ExtentReporter.InitializeCurrentFeatureContext(); 
            }
        }

[BeforeScenario]
        protected static void InitializeScenarioContext()
        {
            if (IsExtentReportsEnabled)
            {
                ExtentReporter.InitializeCurrentScenarioContext();
            }
        }

Which is basically doing both steps separately in different tags, thanks again

rudreshtrivedi commented 5 years ago

Welcome