0

I am planning to work on the Cucumber feature file with Groovy code (Katalon Studio) for step definitions. I wanted to use the excel file in Cucumber file or to see is there any other option to use it.

I have not yet tried as of now any other option. I am thinking just passing the cucumber step file without any parameter and then using the excel file with in the step definition and access excel file and get the corresponding value.

I see there is a post in this forum suggesting to use QMetry Automation Framework for this type of question. But it does not look like this will help on this or should I use the passing the row index from cucumber file and based on that retrieve the value. Please guide on this.

Handling excel spreadsheets with Cucumber Scenario Outline

Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
Venkat D
  • 41
  • 6
  • Possible duplicate of [Using rest data through CSV file in Cucumber](https://stackoverflow.com/questions/49931075/using-rest-data-through-csv-file-in-cucumber) – Marit Jun 04 '19 at 13:08

2 Answers2

3

You should know that this is not supported by Cucumber.

As specified in the FAQ:

"We advise you not to use Excel or csv files to define your test cases; using Excel or csv files is considered an anti-pattern.

One of the goals of Cucumber is to have executable specifications. This means your feature files should contain just the right level of information to document the expected behaviour of the system. If your test cases are kept in separate files, how would you be able to read the documentation?

This also means you shouldn’t have too many details in your feature file. If you do, you might consider moving them to your step definitions or helper methods. For instance, if you have a form where you need to populate lots of different fields, you might use the Builder pattern to do so."

Marit
  • 2,399
  • 18
  • 27
  • **Thank You so much, Marit for your clarification.** As mentioned in my question, I am using the Cucumber & Groovy, I am planning to keep the test data in the excel file and read/pass the test data to my test cases during the execution. OR instead of passing the data in cucumber file, shall I pass the reference row number through cucumber feature file and read the excel sheet in the Groovy Script (step definition) alone ? I can pass the parameters in cucumber with scenario outline, but I wanted to use the excel file as I will have many columns in few of the test cases ! Can you please advise? – Venkat D Jun 04 '19 at 06:13
  • 1
    The idea of using Gherkin is that the scenarios are human readable. That will not work if you store the test data in Excel. Cucumber's opinion is: don't store test data in Excel. (Which is why it is not supported!). Use the test data that is needed to understand a specific Scenario / Example in the Gherkin (feature file), and put the rest of the data you need in a helper method. You can use the [builder pattern](https://en.wikipedia.org/wiki/Builder_pattern) to build your objects. – Marit Jun 04 '19 at 13:02
  • **Really appreciate your help, Marit** I can pass the data through Scenario outline as parameters. But using the excel it would be more clear and can control the execution also. what do you suggest on when I just use cucumber steps without parameter and import the excel sheet in the groovy script and pass the values ? OR passing reference no through scenario outline from cucumber and get the particular row in excel sheet at groovy script. how does it work ? You mentioned about **builder pattern, can you please suggest with** **example how I can use in my test ?** – Venkat D Jun 05 '19 at 07:11
  • I'd suggest **either** using Cucumber, **OR** using Excel. I cannot help you with how to read your data from Excel in Groovy. Have a look at Apache POI. – Marit Jun 05 '19 at 07:23
  • **Thank you so much, Marit.** Yeah.. I looked at the Apache POI and I see these constructors are being used in Groovy for excel retrieval. In this case, I will not be using the cucumber feature file. Now, it is clear that I can use either Cucumber or Excel File. What do you suggest for the best option using parameters through cucumber feature file **OR** excel file reading in Groovy ? – Venkat D Jun 07 '19 at 07:17
  • I'd recommend using Cucumber as intended, over reading from an excel file (I have done both, but much prefer Cucumber). If you have a lot of fields to populate, you can use the builder pattern to create your object, rather than mention all parameters in the feature file. If you need different versions, you can use different steps / methods, for example "Given a regular order" (with basic builder), "Given an order with additional x" (basic builder + additional x), etc. Hope this makes sense. For help with Cucumber, please try one of the [Cucumber support options](https://cucumber.io/support). – Marit Jun 08 '19 at 10:14
  • **Thank You so much.** I will proceed with the cucumber feature files. I am new to the builder pattern and can you please give me one small example about this how to build it. – Venkat D Jun 10 '19 at 11:06
  • @VenkatD - check the link to Wikipedia for examples. – Marit Jun 20 '19 at 06:25
0

If you are using cucumber java 5+ you can add qaf-cucumber dependency. It should work with groovy as well. It will enable to have examples from external source like CSV, XML, JSON, EXCEL, DB.

user861594
  • 5,733
  • 3
  • 29
  • 45