简体   繁体   中英

Using environment variables in my cucumber step definitions

I want to change a step definition from something like,

Scenario: eat 5 out of 12
  Given there are 12 cucumbers
  When I eat 5 cucumbers
  Then I should have 7 cucumbers

To,

Scenario: eat 5 out of 12
  Given there are 12 $(FOOD)
  When I eat 5 $(FOOD)
  Then I should have 7 $(FOOD)

So that I can run my cucumber like,

FOOD=cucumbers ./cucumber-launch-script.sh

And everything works as expected.

You can sort of do this but the environment variable can only be used in code, ie step definitions and helper methods.

This means that your output will only be talking about FOOD whilst your steps would be talking about oranges and apples.

This would work something like

Given there are 12 food

implemented by

Given 'there are 12 food' do 12.times {create_food) end

and a helper method

def create_food type_of_food = get food from ENV ... end

The only way to get environment variables into features is to preprocess them before you run cucumber, I can't see Cucumber ever supporting this sort of functionality.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM