简体   繁体   中英

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

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.

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'}

If you want to process a big chunk of data with many examples in a single scenario you can do the following

  1. Give the set of examples a name eg foo_data
  2. Write a scenario that talks about foo_data as a single entity

     Given ... When I bar with foo_data Then I should see no foo_data errors 
  3. Write a single call step definition to process all your data

     When "I bar with foo_data" do bar_with_foo_data end 
  4. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM