Writing to SpecFlow HTML reports

We can write to HTML report generated in SpecFlow using Console.WritLine method as shown in below example.

using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Firefox;
using System;
using TechTalk.SpecFlow;

namespace SpecFlowRunnerProject
{
    
    public class BaseStep
    {
        protected MySharedThings things;

        public BaseStep(MySharedThings sharedThings) {
            this.things = sharedThings;
        }

        [BeforeScenario]
        public void before()
        {
            Console.WriteLine("Running feature -> "
                + FeatureContext.Current.FeatureInfo.Title);

              Console.WriteLine("Running Scenario -> " 
                  + ScenarioContext.Current.ScenarioInfo.Title);

            things.driver = new FirefoxDriver();
            Console.WriteLine("Launching firefox");
        }

      

        [AfterScenario]
        public void after()
        {
            if (ScenarioContext.Current.TestError != null)
            {
                Console.WriteLine("An error Message -> " 
                    + ScenarioContext.Current.TestError.Message);

                //Here we can take screenshot
                        
            }
            things.driver.Close();
            things.driver.Quit();
        }

    }
}

Here is the HTML report showing the messages logged by Console.WriteLine

Writing to html report in SpecFlow

Writing to html report in SpecFlow

You may also like...