I have a scenario where i need to execute a scenario in a feature file multiple times as long as the Test Data is present in the Excel. Each row of the Excel has a different set of test data. I want the feature to run 'n' times for 'n' sets of test data present in the excel rows.

I researched and found that there are no looping controls in cucumber. However i couldn't think of a way to do it and hence no code.

Is there a way to achieve this ? Please help.

  • You can use Transformer class to integrate Excel with Cucumber framework
    – user35355
    Oct 26, 2018 at 5:43

3 Answers 3


Cucumber has Scenario Outline with Examples to 'loop' over the same Scenario with different test cases. You can use it like this:

Scenario Outline: eating Given there are cucumbers When I eat cucumbers Then I should have cucumbers

Examples: | start | eat | left | | 12 | 5 | 7 | | 20 | 5 | 15 |

Use 'Scenario Outline' instead of Scenario. Use as placeholders for the variables you want to use in your test cases. Make sure the names of the placeholders match the column names in your Examples table. And make sure the 'Examples' keyword is aligned with the Given/When/Then keywords.

If on the other hand, you must use excel for the test cases for some reason, Cucumber might not be the framework to use. Be aware that I/0 (reading from a file) is expensive (takes longer), so it will slow down your tests.


No you don't. Cucumber is a BDD framework. Which means the feature files specify your scenarios. What you're asking for is reading the scenarios (or part of it) from an excel file, which effectively hides it from cucumber and doesn't fit the purpose. From this point you have two options: 1. Get rid of the excel by converting it into cucumber table(s) with scenario outline, as @Marit suggests. 2. Keep the excel file, but use a different way to execute your test. For example, JUnit. You can still reuse the glue for the cucumber steps if needed.


You can write a tool to read the excel file and inject into the .feature files as Scenario Outline, running it before your tests.

It could read a tag which indicates a excel file.


Scenario: bla bla bla






Scenario: bla bla bla




| col1 | col2 |

| val11 | val12|

| val21 | val22|


Apache has a library in Java for manipulating Excel files and to replace the tag, you can use the regex library of your favorite language.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.