Specflow Tutorial
Introduction to SpecFlow Installation of SpecFlowWriting first SpecFlow test in Visual Studio Writing step definitions for a SpecFlow feature file Executing SpecFlow scenarios and feature files Using SpecFlow runner to execute the feature files Using tags in SpecFlow Passing parameters to steps Data table in SpecFlow Scenario Background Scenario outline Hooks in SpecFlow Executing Selenium tests with SpecFlow Executing the failed test multiple times Sharing selenium Webdriver instance in SpecFlow Writing to SpecFlow HTML reportsSpecflow HTML report
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
Web development and Automation testing
solutions delivered!!