How can I use variables in my feature file? Specifically, I need to use dateTime.now
. Ideally, something like...
Given the API returns items for "dateTime.now"
when my function is run
then I want that data in my database
And in my acceptance test file...
[Given("The API returns line items for (.*)")]
Is this the proper way to go about this? I'm unsure of how to use variables in my feature file. I want my acceptance test to use the current date.
The easiest way is to write a step specific for returning lines items for "right now":
Given the API returns items for right now
You can call the other version of the step from the new version:
[Given(@"the API returns items for right now")]
public void GivenTheAPIReturnsItemsForRightNow()
{
GivenTheAPIReturnsItemsFor(DateTime.Now);
}
This avoids code duplication between steps.