Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass variable in feature background "Given" statement in cucumber?

@TestHomeValidation
Feature:copy function test

  Background:
    Given I am running test in "VARIABLE" environment

Can I use VARIABLE in above background given statement? I want to pass this VARIABLE value from properties file.

like image 334
Manoj Mali Avatar asked Feb 07 '17 05:02

Manoj Mali


3 Answers

You can achieve this with QAF gherkin client.

@TestHomeValidation
Feature:copy function test

  Background:
    Given I am running test in "${my.env}" environment

Provide your my.env in property file. Further more you can have environment specific resources that you can configure with QAF

like image 184
user861594 Avatar answered Oct 21 '22 10:10

user861594


I afraid you want be able to use external data source for storing variables to provide to Cucumber steps. What you might consider us using DataTables Scenario Outlines. In both cases you can provide some local(intra-feature file) parameters. For example:

Scenario: Scenario1 
  Given I have done "this" #this can be parsed by the glue code
  Then these can be used: #You can use DataTable type to parse multiple groups of variables
    | col1 | col2 | col3 |
    | x    | x1   | x2   |
    | y    | y1   | y2   |


Scenario Outline: <col1> test 
  Given I have done "<col2>"
  Then I can see "<col3>"
    | col1 | col2 | col3 |
    | par1 | par2 | par3 |
like image 24
Eugene S Avatar answered Oct 21 '22 11:10

Eugene S


Like @eugene-s mentioned this is not possible out of the box.

I have a similar case where I need to substitute and possible add more variables from external file.

The solution we going for is to parse the features with Gherkin parser, put in the values and create new tree which can be either written to a new file and passed along or substituted directly in the test runner.

if interested you can follow the development here

like image 23
kalin Avatar answered Oct 21 '22 10:10

kalin