Variables in feature file

3,174 views
Skip to first unread message

dam

unread,
Jan 27, 2012, 7:10:30 PM1/27/12
to Behat

I would like to use variables in feature file and evaluate variables
before step execution.

For example:
$EnWikiVariable = "en.wikipedia.org"
$FrWikiVariable = "fr.wikipedia.org"

Given I navigate to "EnWikiVariable"
Then the url should match "EnWikiVariable"
Given I navigate to "FrWikiVariable"
Then the url should match "FrWikiVariable"

Appreciate if there are any example of such implementation. Thanks.

Christophe COEVOET

unread,
Jan 27, 2012, 7:26:25 PM1/27/12
to be...@googlegroups.com
Le 28/01/2012 01:10, dam a �crit :
what you want seems exactly what scenario outlines are for. Check the
doc here: http://docs.behat.org/guides/1.gherkin.html#scenario-outlines

--
Christophe | Stof

dam

unread,
Jan 27, 2012, 7:30:13 PM1/27/12
to Behat
My apology, I guess I was not clear enough. I want to switch between
environment and use different set of test data. I am thinking of
reading data from property file into variable. These variables should
be evaluated first before the step execution.

Thanks.

dam

unread,
Feb 3, 2012, 2:10:27 PM2/3/12
to Behat
Bump

Thibaud Lepretre

unread,
Apr 4, 2013, 11:48:44 AM4/4/13
to be...@googlegroups.com
I'm looking for the same feature.

I can create my own "variable translator" using Hook beforestep.

For exemple a step using "%VAR1%" on beforestep hook I can change %VAR1% for a desired value.

But it's may exists another, or proper way to do that?

Because I need different value per environment level (dev, staging etc ...)

Marijn Huizendveld

unread,
Apr 4, 2013, 12:27:04 PM4/4/13
to be...@googlegroups.com
-1. Gherkin is not a programming language. Its a domain specific language that should describe your feature in the language of the beneficiary. It's not meant to be a programming language for testing your code.

Konstantin Kudryashov

unread,
Apr 5, 2013, 6:22:06 AM4/5/13
to be...@googlegroups.com

That's the exact reason we have `behat.yml` context parameters and relative urls in features.

All environment-specific config should be put inside `behat.yml` and that's your job as a

FeatureContext developer to use them in steps. But, at the same time, your *.feature files

should stay readable for your stakeholders (non-technical people in most cases). Leave

programming details to programming layer (contexts).


Konstantin Kudryashov
--- PHP developer, BDD evangelist, Scrum master

a: http://about.me/everzet
b: http://everzet.com
c: https://github.com/everzet

On 28 January 2012 at 01:30:13, dam wrote:

My apology, I guess I was not clear enough. I want to switch between
environment and use different set of test data. I am thinking of
reading data from property file into variable. These variables should
be evaluated first before the step execution.

Thanks.

On Jan 27, 4:26 pm, Christophe COEVOET <s...@http://notk.org> wrote:
> Le 28/01/2012 01:10, dam a crit :> I would like to use variables in feature file and evaluate variables
> > before step execution.
>
> > For example:
> > $EnWikiVariable = "http://en.wikipedia.org"
> > $FrWikiVariable = "http://fr.wikipedia.org"
>
> > Given I navigate to "EnWikiVariable"
> > Then the url should match "EnWikiVariable"
> > Given I navigate to "FrWikiVariable"
> > Then the url should match "FrWikiVariable"
>
> > Appreciate if there are any example of such implementation. Thanks.
>
> what you want seems exactly what scenario outlines are for. Check the
> doc here:http://http://docs.behat.org/guides/1.gherkin.html#scenario-outlines
>
> --
> Christophe | Stof

tim.for...@gmail.com

unread,
Jun 20, 2016, 9:19:43 AM6/20/16
to Behat
RESTFul web testing ... I am updating a variable in a transformation.
The request that actually goes to server reflects the variable change.
But the log output for the request does not contain the change.

Is this a valid case for having a variable in the feature file ?
Reply all
Reply to author
Forward
0 new messages