Search This Blog

Breaking

Thursday, 24 September 2020

September 24, 2020

Dynamic data from cucumber feature file

 Recently, I came across to one scenario where I need to pass a random value from a feature file and later the same value, I need to validate also in another feature file step. So to implement this, I followed the below approach.








I created a global variable in my step definition file. 

let randomValue = ``;

Later from feature file, I wrote feature file like:

when I type "RANDOM_VALUE"

And in its implementation, I use this string as a condition.

if (value=== `RANDOM_VALUE`)

{

//Here I created a string with the current date/time

let d = new Date();

randomValue = d.getHours().toString() + d.getMinutes().toString()+ d.getSeconds().toString();

browser.type(randomValue);


}

This allows me to type a random value from the feature file which in subsequent steps we can reuse for 

validation purposes also.

Same thing you can do from the cucumber feature file example also.

Given I type "< RANDOM_LAST_NAME >"


  | FirstName | RANDOM_LAST_NAME|

  | alice          | test                                 |

  | bob           RANDOM_VALUE          |