Are there any methods of passing static variables from a class into a Cucumber feature file?

34 Views Asked by At

Background:

I have built an extremely powerful automation framework that uses Cucumber, Junit, Selenium, and DataFaker to achieve dynamic front-end automation. Essentially there is a method within my code tied to a step definition that will initialize around 300+ dynamic variables when you call it. This allows testers to create scripts where the values will always be unique every time but also make sense. As an example, there is one variable called fAddressStateAbbr. This gets the state abbreviation. From there I wrote a method to convert it into a full name and then I used DataFaker to find a valid zip for the state and to find the county. As you can imagine this type of power is very useful. If anyone is curious what they are looking at it's an incident tracking tool used by NOAA for patrols in the ocean.

Limitation/Problem:

As far as I know, you must only use static values or data tables in a feature file. While the step that sets the values can be called you must use a project step-definition to access the static variables. If there was some way I could reference those variables in the feature file after they were set in the required step it would mean that testers would have the choice between using feature files or custom steps for dynamic variables and could be very nice. I've done some research but nothing I've found is what I'm looking for so any advice can help.

Screenshots:

enter image description hereThis screenshot demonstrates the method I'm using to set thet dynamic variables. I only included it to help people understand how I'm using DataFaker and why it's so useful to me.

enter image description here

Right now this is the only way that we can use the dynamic variables. We have to create a custom step-definition and then we can reference them. I know this looks a bit odd because it's Appian but it's basically just using Selenium on the back-end their logic is just so complex they have to create those fixture methods to translate it.

enter image description here

For the previous screenshot here is how we would normally call it in the feature file. So the desire is that if we had a page with maybe only one or two fields we needed to automate dynamically we could just reference those variables in our feature file instead of having to create such a small step-definition.

I did a Google Search on "passing in variables to a feature file." This resulted mostly in ways of passing in static data from outside sources or between steps. Although now I wonder, if you used a Cucumber hook to make the data generate and then you used the scenario context to pass the data into the step maybe it would work?

0

There are 0 best solutions below