0

I have 4 scenarios, for example:

Scenario: test single unit transaction
Given Scene is set
When We did something
Then
 | header1 | unit  | etc. |
 | data1   | data2 | ...  |

Scenario: test multiple unit transaction
Given Scene is set
When We did something
Then
 | header1 | unit  | etc. |
 | data1   | data2 | ...  |
 | data3   | data4 | ...  |

Scenario: test single percentage transaction
Given Scene is set
When We did something
Then
 | header1 | percentage | etc. |
 | data1   | data2      | ...  |

Scenario: test multiple percentage transaction
Given Scene is set
When We did something
Then
 | header1 | percentage | etc. |
 | data1   | data2      | ...  |
 | data3   | data4      | ...  |

They are a lot more complicated and longer, so I'd like to achieve something like this:

Scenario Outline: test transactions
Given Scene is set
When We did something
Then
 | header1 | unit    | etc. |
 | <data1> | <data2> | ...  |
Examples: single transaction
 | header1 | unit    | etc. |
 | data1   | data2   | ...  |

Examples: multiple transaction
 | header1 | unit   | etc. |
 | data1   | data2  | ...  |  --------> these should run together in one test
 | data3   | data4  | ...  |  -------->

And the same for the other type of transaction.

Unfortunately, Cucumber keeps running the above as 3 different scenarios, instead of 2, and the sencond one with 2 transactions. Does anyone have any idea how to make it work?

Thanks a lot.

monami
  • 594
  • 2
  • 9
  • 32

1 Answers1

1

As far as I know when using Scenario Outline with Examples, it will run for as many rows you have definded in the examples table, so Cucumber is working right for your examples.

Not sure what you're trying to do in those scenarios but if you want to use Scenario Outline I think you need to restructure the Examples or you could try something like this (untested and it can probably get more complicated):

Scenario:

Scenario: test transactions
  Given the scene is set
  When we did something
  Then something should happen:
  | header1 | unit  |
  | data1   | data2 |
  | data3   | data4 |

Steps: With a Data class:

@Then("^something should happen:$")
    public void explosionsHappen(List<Data> entries) {
        for (Data entry : entries) {
            //Do stuff to each entry without restarting the scenario
        }
    }

public class Data {
    String header1; 
    Integer unit;
}

With a Datatable:

@Then("^something should happen:$")
public void explosionsHappen(DataTable data) throws Throwable {
    for (Map<String, Integer> data : data.asMaps(String.class, Integer.class)) {
            //Write code to handle Datatable
        }
}

More on this here and here. For the second link, go through the features / steps and check how they were implemented.

There could be other ways to do what you want. Hope this helps!

Daniel Fintinariu
  • 2,733
  • 1
  • 14
  • 16
  • It helped, thanks, I now know I should better phrase my questions :) The problem is exactly that cucumber iterates the test as many rows we add, but my point would be: feed the two rows to one test only, because I need them in one scenario at one time (as repeating steps, but not with a single param but with data table), and only one row at an other time (that's the two types of examples) – monami Aug 08 '17 at 12:59
  • Thanks for the 2nd link, basic_arithmetic.feature (Given the previous entries) seems promising, but my parameters are in table, not in single amounts. Still not sure how to solve this. – monami Aug 08 '17 at 13:51
  • If it gets too complicated, better create one `Scenario` in which you check a single transaction (no example table needed) and a second one in which the last step hadles the Datatable (like in the examples). It's a matter of writing two different steps. – Daniel Fintinariu Aug 08 '17 at 14:13
  • 1
    Actually, no, what I could do is to reduce them to 3 scenarios, and the single transactions could go to an outline with `unit` and `percentage` in the same table, but multitransaction has two scenarios for the different types, because handling the two rows in the table in one test is not working with outlines. Anyway, thanks for your efforts in helping me! – monami Aug 10 '17 at 09:56
  • Gald you made it work. I was a bit confused on what you were trying to achieve and what the context of the scenarios were. – Daniel Fintinariu Aug 10 '17 at 10:21