Loading parameters from an external resource in cucumber

1,829 views
Skip to first unread message

Bogdan Puiu

unread,
Apr 6, 2015, 5:18:44 PM4/6/15
to cu...@googlegroups.com
Hello,

I'm in process of migrating some tests from jBehave to Cucumber and I've stumbled onto an issue that I'm not really sure that there is any support for.
To get the item - Cucumber lets me write this:

Scenario Outline: eating
  Given there are <start> cucumbers
  When I eat <eat> cucumbers
  Then I should have <left> cucumbers

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


Can I externalize the examples?
Examples: file.table

Like the jBehave implementation - http://jbehave.org/reference/stable/parametrised-scenarios.html (scroll to

Loading parameters from an external resource)

Or - does anyone know of a similar solution of parametrization?


Thanks,

Bogdan



aslak hellesoy

unread,
Apr 6, 2015, 6:00:18 PM4/6/15
to Cucumber Users
Cucumber doesn't let you put the examples table in a separate file.

Why would you want to do that?

Aslak 


Thanks,

Bogdan



--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

George Dinwiddie

unread,
Apr 6, 2015, 8:23:57 PM4/6/15
to cu...@googlegroups.com
Bogdan,

On 4/6/15 3:48 PM, Bogdan Puiu wrote:
> Hello,
>
> I'm in process of migrating some tests from jBehave to Cucumber and I've
> stumbled onto an issue that I'm not really sure that there is any
> support for.
> To get the item - Cucumber lets me write this:
>
> Scenario Outline: eating
> Giventhere are<start> cucumbers
> WhenI eat<eat> cucumbers
> ThenI should have<left> cucumbers
>
> Examples:
> |start |eat |left |
> |12 |5 |7 |
> |20 |5 |15 |
>
>
> Can I externalize the examples?
>
> Examples:
> file.table
>
> Like the jBehave implementation - http://jbehave.org/reference/stable/parametrised-scenarios.html (scroll to
>
>
> Loading parameters from an external resource)
>
> Or - does anyone know of a similar solution of parametrization?

While Cucumber can't pull an examples table from an external file, I've
created a step definition that loaded data from a spreadsheet. I did
this because an external test team was responsible for loading the
testing database, and they could create the spreadsheet, too, to
indicate the proper data for test cases.

I don't recommend it. The use of executable specifications failed at
this client because they wanted to use cucumber purely as a testing
tool, not a collaboration tool. The lack of collaboration became a big
issue (more than just related to Cucumber), and thus Cucumber didn't
provide a lot of value. They were also writing their scenarios in a Word
requirements document, and then pasting them into the Feature files,
also without collaboration.

- George

--
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------

Selenium Vietnam

unread,
Dec 31, 2015, 3:04:43 AM12/31/15
to Cukes
Plain text is like living document. And if your document is too ugly with a lots of column in the feature file. It is not nice view for PO or BA. They don't care about dataset.

They only take care scenario content. It is no problem if in EXAMPLES part there are some column.

Andrew Premdas

unread,
Dec 31, 2015, 12:17:32 PM12/31/15
to cu...@googlegroups.com
On 31 December 2015 at 08:04, Selenium Vietnam <vuthel...@gmail.com> wrote:
Plain text is like living document. And if your document is too ugly with a lots of column in the feature file. It is not nice view for PO or BA. They don't care about dataset.

Agreed, but thats no reason to put the dataset in an external file and then munge it into the plain text. Instead let the step definitions pull data from whatever source and do whatever is needed. Write your scenarios to allow this to happen by naming your datasets and talking about them a more abstract fashion.

Happy New Year

A
 



--
------------------------
Andrew Premdas

Areg Gareginyan

unread,
Jan 25, 2016, 5:05:43 PM1/25/16
to Cukes
Let me describe you a situation where having the datasets in external files is helpful. We have REST API automated cases in Cucumber that should be executed against different environments (DEV, QA, PROD). Datasets for all these environments (e.g. users / passwords) are different from each other. The approach that we took to achieve our goal is to specify the environment as a Java system property (via -D command), and then loading the datasets from the corresponding files. 

In my opinion, this can be solved by having 2 more features in Cucumber:
- support of cmd line parameters (e.g. using [parameter_name] syntax in feature files)
- support of "Examples: <file_name>" directives

Paolo Ambrosio

unread,
Jan 25, 2016, 5:18:15 PM1/25/16
to cu...@googlegroups.com
On Mon, Jan 25, 2016 at 1:51 PM, Areg Gareginyan
<areg.ga...@gmail.com> wrote:
> Let me describe you a situation where having the datasets in external files
> is helpful. We have REST API automated cases in Cucumber that should be
> executed against different environments (DEV, QA, PROD). Datasets for all
> these environments (e.g. users / passwords) are different from each other.
> The approach that we took to achieve our goal is to specify the environment
> as a Java system property (via -D command), and then loading the datasets
> from the corresponding files.
>
> In my opinion, this can be solved by having 2 more features in Cucumber:
> - support of cmd line parameters (e.g. using [parameter_name] syntax in
> feature files)
> - support of "Examples: <file_name>" directives

The Cucumber features you propose would add technical details into
feature files, that is exactly the opposite of what Cucumber is about.

Why should stakeholders know that there is a file to be read that has
some data that is needed by the glue code? If you need that, your
features are probably not readable by the stakeholders without
previous knowledge (e.g. knowing what should be in those files), and
you are likely using Cucumber as a test automation tool.


Paolo

Roberto Lo Giacco

unread,
Jan 26, 2016, 7:30:19 AM1/26/16
to Cukes


Il giorno lunedì 25 gennaio 2016 23:18:15 UTC+1, Paolo Ambrosio ha scritto:

The Cucumber features you propose would add technical details into
feature files, that is exactly the opposite of what Cucumber is about.

Why should stakeholders know that there is a file to be read that has
some data that is needed by the glue code? If you need that, your
features are probably not readable by the stakeholders without
previous knowledge (e.g. knowing what should be in those files), and
you are likely using Cucumber as a test automation tool.


I couldn't have said that in a better way! 

Jabbar Ali Mirza

unread,
Jun 23, 2016, 4:34:08 PM6/23/16
to Cukes
Hi All,

I have similar requirement where the data should come from external source like .csv or .xls to the .feature (scenario outline)..

Just wondering has any one implemented this, appreciate some code on using java / selenium.

Thanks

Regards
J

Justin Radcliffe

unread,
Jun 23, 2016, 7:44:30 PM6/23/16
to Cukes
Could you just load the data in the step definitions on the java side? Then you could use Apache POI to parse through the rows.

Also, if you can get away with one tab, use cvs as that will be able to be compared by versions in source control unlike xls.
Reply all
Reply to author
Forward
0 new messages