Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cucumber tests - break example table of scenario outline into smaller chunks

I have a big example table in scenario outline with around 20 columns

 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
like image 666
mihir S Avatar asked Dec 14 '25 10:12

mihir S


2 Answers

One way is by using gherkin with qaf where it supports examples provided in external file excle/csv/xml/json or database. In that case your scenario may look like:

Scenario Outline: ....
    Given ....
    When ...
    Then ....
    Examples:{'datafile':'resources/testdata.xls'}
like image 190
user861594 Avatar answered Dec 16 '25 09:12

user861594


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. The excel or db will have a unique key column which will need to match the row index in the examples table.

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 -

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.

like image 28
Grasshopper Avatar answered Dec 16 '25 09:12

Grasshopper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!