0

给定一个 Excel 文件,如何以编程方式生成特征文件?

使用 Specflow 2.3.2 和相应的 Excel 插件和 dotNet 框架(不是 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 ??
4

1 回答 1

0

FeatureFile 是使用生成的

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

完整代码:

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 );
于 2020-09-01T04:48:10.447 回答