How to parse data into cucumber's variables in feature file?

38 views Asked by At

I'm currently working a UI selenium project in which I want to get the String data from the UI and parse it into a variable in my .feature scenario file.

I will use this scenario to explain, in this case, I only have the customerID:

Given I search for customer A

When I get the customer info: customer name and last orderID in customer general info page

Then I compare it with the actual last orderID in the order list to see if the customer name and the last orderID are matching.

Example:

|customerID|customername|lastOrderID|
|3434423432|  ???       |  ??       |

I would like to get String data of the customername and lastOrderID from the UI and parse these values into the cucumber variables. What should I do here? Btw, this is the first time I send a question on stackoverflow, so appologize if my info is being explained vaguely. Much appreciate for any helps!

I have looked around on the Internet for help, but I'm kinda stuck here.

1

There are 1 answers

0
sashkins On

If I got you right, you want to capture some data in one step, and then use this data in some other step. It is called 'sharing the state' between steps.

To do this, you need to create some Class for holding the properties you want, and then inject an instance of that class in the required step definition classes.

See the official docs about the State.

Also, there is a good article about one of the most popular in the Cucumber world DI frameworks - PicoContainer (due to its simplicity and unobtrusiveness). The example provided in that article has some similarities with your case, so you can just read it and follow along.