I am pretty new to Specflow and I'm trying see if this is possible with Specflow BeforeFeature Hook. I have some dynamic test data setup that is only for a particular feature. I want to use these test data values as part of the scenario test. This is one of the scenario tests of the feature file:
@logintest
Feature: User login
Scenario: User login with different product access
Given I am in <productType> login page
When I login as <user>
I should see <productType> logo in my account
Inside the BeforeFeature(), we have functions that generate: -a random user account that has a property of product access type - random urls for a product login page. (e.g: productA234234.dev.local)
[Binding]
public class LoginHooks
{
[BeforeFeature("logintest")]
public static void BeforeFeature()
{
UserAccount testUser = new UserAccount(productType1);
var product1Url = CreateProductUrl(productType1);
FeatureContext.Current.Set("testUser", testUser);
FeatureContext.Current.Set("productUrl", productUrl);
...
}
Because the username is generated randomly each time on tests run, I couldn't provide the username to the Gherkins as part of data tables etc. Is there a way to construct the Gherkins to take in values from FeatureContext?
[Binding]
public class UserLoginSteps
{
//var productUrl = ???
[Given(@"I am in (.*) login page")]
public void GivenIAmInLoginPage(string productUrl)
{ . . .}
}
Question:
- is it possible to get FeatureContext values for the productUrl and set in the step?
- I think the regex Given is incorrect in such case. Is there another way to construct it to take a variable as part of the data input?
Thanks!