SpecFlow+ Excel Generate Feature File Programmatically

134 Views Asked by At

Given an Excel file, how could a feature file is generated programmatically ?

Using Specflow 2.3.2 and corresponding Excel plugin and dotNet Framework (NOT dotNetCore)

string excelPath = @".\CalculatorAdd.feature.xlsx";

ExcelParser excelParser = new ExcelParser( CultureInfo.CurrentCulture, CultureInfo.CurrentCulture );

var specFlowDoc = excelParser.ParseExcel(excelPath);

// all the scenarios are in this specFlowDoc, 
// just need to export it as feature file, no need to generate code-behind.
// what is next ??
1

There are 1 best solutions below

0
On

FeatureFile is generated using

var docFormatter = new SpecFlow.Plus.Excel.SpecFlowPlugin.DocumentFormatter();
string featureFileStr = docFormatter.GetDocumentText(specFlowDoc);

Full Code:

string excelPath = @".\CalculatorAdd.feature.xlsx";

ExcelParser excelParser = new SpecFlow.Plus.Excel.SpecFlowPlugin.ExcelParser( CultureInfo.CurrentCulture, CultureInfo.CurrentCulture );
var specFlowDoc = excelParser.ParseExcel(excelPath);

var docFormatter = new SpecFlow.Plus.Excel.SpecFlowPlugin.DocumentFormatter();
string featureFileStr = docFormatter.GetDocumentText( specFlowDoc );