We have current framework in Jbehave where we have large number of test data stored in JSON file and using Parameterconverter to pass value to JBehave stories based on specific environment. I am working on switching framework to Cucumber and wondering if I can use same JSON files or not
-
In general, my answer would be that you can pass values from a file, but you would have to do so in the code, not the feature file. Maybe you can provide a real world example of what you would like to do?Marit– Marit2019-02-28 12:31:37 +00:00Commented Feb 28, 2019 at 12:31
-
Not sure but I guess, You can pass the JSON file path from your feature file inside double quotes. Now, you can create your custom DataTable. In your custom DataTable, accept the file path string. While creating custom DataTable, you will require to implement Transformer Interface and provide the implementation for "public Object transform(String filepath)". Inside this method, read your JSON file using the filepath and return a DataTable object. Hope this link might help you. youtube.com/watch?v=x7UVqzqf_5Ukwishna– kwishna2019-02-28 15:50:23 +00:00Commented Feb 28, 2019 at 15:50
Add a comment
|
1 Answer
Cucumber dosen't support data out side the feature file or from external file . What you are looking for is supported with qaf by use of json data provider. With QAF your scenario can look like below:
@dataFile:resources/${env}/data/logintestdata.json
Scenario: example
Given use is on login page
When login using '${username}' and '${password}'
And store into 'status'
Then verify that '${status}' is '${isvalid}'
And verify error message '${expected_msg}'
In above example, value of ${env} in data file path can be provided at the time of execution in different ways.This is just as an example. There can be other alternative ways by using different features of qaf depending on need.
2 Comments
alok barman
I am looking for this data file implementation. Do you refer any open github repo to see the implementation?
user861594
(qaf-blank-project-maven)[github.com/qaf-tm/qaf-blank-project-maven] is the best place to start. It provides a skeleton project structure showing exactly where to place data files (the resources directory) and how they are utilized in a Maven-based environment