[英]Cucumber tests - break example table of scenario outline into smaller chunks
I have a big example table in scenario outline with around 20 columns 我在方案大纲中有一个很大的示例表,大约有20列
Scenario Outline: ....
Given ....
When ...
Then ....
Examples:
|col1|col2|col3|col4|col5|........|col20|
|val1|val2|val3|val4|val5|........|val20|
Is it possible split examples table into smaller chunks like this 是否可以将示例表拆分成较小的块,像这样
Examples:
|col1|col2|col3|col4|col5|
|val1|val2|val3|val4|val5|
|col6|col7|col8|col9|col10|
|val6|val7|val8|val9|val10|
....upto 20
Each row of the examples table denotes one scenario run. 示例表的每一行表示一个方案运行。 If you break up the row then certain values in each scenariooutline run will not have values and also you will have more runs then actual required. 如果将行分开,则每个方案大纲运行中的某些值将没有值,并且您将有更多运行,而实际需求除外。 So the answer is no. 所以答案是否定的。
What you can try to do is store the all the data or some outside the feature file, in an excel file or even a database. 您可以尝试将所有数据或功能文件外部的某些数据存储在excel文件甚至数据库中。 The excel or db will have a unique key column which will need to match the row index in the examples table. excel或db将具有一个唯一的键列,该键列需要与示例表中的行索引匹配。
Feature file - 功能文件-
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 code - 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
}
This has its pros and cons. 这有其优点和缺点。 You are separating data from feature file. 您正在从功能文件中分离数据。 Introducing technical details in scenarios. 介绍方案中的技术细节。 Loosing capabilities of data matching and transformation in steps. 逐步失去数据匹配和转换的能力。 Major pro data is manageable. 主要的专业数据是可管理的。
One way is by using gherkin with qaf where it supports examples provided in external file excle/csv/xml/json or database. 一种方法是将gherkin与qaf一起使用,其中它支持外部文件excle / csv / xml / json或数据库中提供的示例。 In that case your scenario may look like: 在这种情况下,您的情况可能类似于:
Scenario Outline: ....
Given ....
When ...
Then ....
Examples:{'datafile':'resources/testdata.xls'}
If you want to process a big chunk of data with many examples in a single scenario you can do the following 如果您想在单个场景中使用许多示例处理大量数据,则可以执行以下操作
Write a scenario that talks about foo_data as a single entity 编写一个场景,讨论将foo_data作为单个实体
Given ... When I bar with foo_data Then I should see no foo_data errors
Write a single call step definition to process all your data 编写一个呼叫步骤定义以处理所有数据
When "I bar with foo_data" do bar_with_foo_data end
Write all you file processing data stuff etc. in the helper method 在辅助方法中写入所有文件处理数据之类的东西
def bar_with_foo_data items = import file ... items.each do |item| bar_with item: item ... end
What you are doing here is pushing the details of how you run the test down into code and out of Cucumber. 您在这里所做的事情是将测试运行的细节简化为代码,而不是Cucumber。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.