2

Is it possible to parametrize @datafile in QAF BDD2? I have the following line in my cucumber feature file

  @dataFile:src/test/resources/testdata.xls

I'd like to be able to use different test data files depending on the environment I run the test in. So I'll have

@dataFile:src/test/resources/env1_testdata.xls

of one environment and

@dataFile:src/test/resources/env2_testdata.xls 

for another

user861594
  • 5,733
  • 3
  • 29
  • 45

1 Answers1

1

Yes, as per documentation, You can use any property in value of meta-data for data provider. It will get resolved using configuration manager. You can utilize this feature as per your convenience. Below are few examples:

#example 1: file with env prefix
@dataFile:src/test/resources/${env.name}_testdata.xls 
#example 2: directory with env name
@dataFile:src/test/resources/${env.name}/testdata.xls
#example 3: sheet with env name
@dataFile:src/test/resources/testdata.xls @sheetName:${env.name}
#example 4: data table with env name
@dataFile:src/test/resources/testdata.xls @key:${env.name}
#example 5: multiple parameters
@dataFile:src/test/resources/${env.name}_testdata_${env.default.locale}.xls 

in above examples, the first one assumes file with env prefix, second example assumes directory with env name, and the third one is sheet in data file with env name. Provided env.name=qa actual values will be resolved as

@dataFile:src/test/resources/qa_testdata.xls 
@dataFile:src/test/resources/qa/testdata.xls
@dataFile:src/test/resources/testdata.xls @sheetName:qa
@dataFile:src/test/resources/testdata.xls @key:qa

Related documentation:

user861594
  • 5,733
  • 3
  • 29
  • 45
  • Thank you! I added env.name=TEST_ENV to resources/application.properties file and it is working perfectly! – user19256804 Aug 23 '22 at 06:53
  • user861594, Do you know if it's possible to set env.name dynamically in the code, or as an environment variable? – user19256804 Aug 23 '22 at 07:33
  • It's a property. refer documentation for [different ways of providing properties](https://qmetry.github.io/qaf/latest/different_ways_of_providing_prop.html). If you want to set using code you can use `setProperty` method. For example, `ConfigurationManager.getBundle().setProperty("propname", val); ` – user861594 Aug 23 '22 at 18:12