我有几个包含多个场景的 Specflow 功能文件,我想针对多个环境(DEV、TEST 和 SIT)执行它们。
所以,我的问题是 - 将环境特定数据从功能文件传递到步骤定义的最佳方法是什么。正如您在下面的示例中所见,员工记录在每个环境中都不同。
Scenario Outline: Employee Search
Given Application is logged
And Search for employee record with <EmployeeName>, <EmployeeID>, <Company>, <Designation> and <Environment>
Examples:
| EmployeeName| EmployeeID| Company | Designation | Environment |
| John Smith 1| 123 | ABC | Analyst | DEV |
| John Smith 2| 456 | DFG | Manager | TEST |
| John Smith 3| 789 | XYZ | Sr Analyst | SIT |
[When(@"Search for employee record with (.*), (.*), (.*), (.*) and (.*)")]
public void WhenSearchEmployee (string EmployeeName, string EmployeeID, string Company, string Designation, string Environment)
{
if (Environment== "DEV")
{
EmployeeRecord.SearchEmployee(EmployeeName, EmployeeID, Company, Designation);
}
else if (Environment== "TEST")
{
EmployeeRecord.SearchEmployee(EmployeeName, EmployeeID, Company, Designation);
}
else if (Environment== "SIT")
{
EmployeeRecord.SearchEmployee(EmployeeName, EmployeeID, Company, Designation);
}
}
编辑
- 我正在用
app.config
文件识别环境
基本上,我想在具有不同数据的多个环境(一次一个)中执行相同的测试用例。另外,如果我在examples
表中有两行,如何根据环境只执行一次。
这是正确的方法吗?谢谢。