SpecFlow + Excel以编程方式生成特征文件

问题描述

给出一个Excel文件,如何以编程方式生成功能文件

使用Specflow 2.3.2和相应的Excel插件以及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 ??

解决方法

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 );

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...