![](/img/trans.png)
[英]Nightwatch/Cucumber - Scenario Outline and Example table not working
[英]Cucumber tests - break example table of scenario outline into smaller chunks
我在方案大纲中有一个很大的示例表,大约有20列
Scenario Outline: ....
Given ....
When ...
Then ....
Examples:
|col1|col2|col3|col4|col5|........|col20|
|val1|val2|val3|val4|val5|........|val20|
是否可以将示例表拆分成较小的块,像这样
Examples:
|col1|col2|col3|col4|col5|
|val1|val2|val3|val4|val5|
|col6|col7|col8|col9|col10|
|val6|val7|val8|val9|val10|
....upto 20
示例表的每一行表示一个方案运行。 如果将行分开,则每个方案大纲运行中的某些值将没有值,并且您将有更多运行,而实际需求除外。 所以答案是否定的。
您可以尝试将所有数据或功能文件外部的某些数据存储在excel文件甚至数据库中。 excel或db将具有一个唯一的键列,该键列需要与示例表中的行索引匹配。
功能文件-
Given Data is stored in file located at //project/module/data/bigscenario.xlsx and use index <DataRowIndex>
Given
When
Then
Examples:
| DataRowIndex |
| 1 |
| 2 |
| 3 |
| 5 | //Even skip index so 4 will not run
StepDefinition代码-
private static boolean dataFlag = false;
private static Map<Integer, DataObject> data = new HashMap<>();
private int rowindex;
@Given("^Data is stored in file located at (.*?) and use index (.*?)")
public void getData(String path, int rowindex) {
if(!dataFlag) {
//Access data from excel using apache poi or db code, and store in map as dataobjects.
dataFlag = true; //Data access runs only for first scenario run.
}
this.rowindex = rowindex; //Key to get data for scenario from map
}
这有其优点和缺点。 您正在从功能文件中分离数据。 介绍方案中的技术细节。 逐步失去数据匹配和转换的能力。 主要的专业数据是可管理的。
一种方法是将gherkin与qaf一起使用,其中它支持外部文件excle / csv / xml / json或数据库中提供的示例。 在这种情况下,您的情况可能类似于:
Scenario Outline: ....
Given ....
When ...
Then ....
Examples:{'datafile':'resources/testdata.xls'}
如果您想在单个场景中使用许多示例处理大量数据,则可以执行以下操作
编写一个场景,讨论将foo_data作为单个实体
Given ... When I bar with foo_data Then I should see no foo_data errors
编写一个呼叫步骤定义以处理所有数据
When "I bar with foo_data" do bar_with_foo_data end
在辅助方法中写入所有文件处理数据之类的东西
def bar_with_foo_data items = import file ... items.each do |item| bar_with item: item ... end
您在这里所做的事情是将测试运行的细节简化为代码,而不是Cucumber。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.