[Given(@"Test data is prepared by feature '(.*)' and scenario '(.*)'")]
public void ExecuteScenario(string feature, string scenario)
{
try
{
// Invoke the other scenario in a separate thread so that context isn't shared
Task.Run(() =>
{
Type type = null;
MethodInfo scenarioMethod = null;
Utils.GetScenarioRelatedMethod(feature, scenario, out type, out scenarioMethod);
var featureInstance = Activator.CreateInstance(type);
// Invoke the scenario set-up method
var setupMethod = type.GetMethod("FeatureSetup");
setupMethod.Invoke(featureInstance, null);
// Get the new test runner and copy the values that we want to share to the feature context
var testRunner = type
.GetField("testRunner", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField)
.GetValue(featureInstance) as ITestRunner;
testRunner.FeatureContext.Fill(FeatureContext);
// Use the same driver for the new test runner
if (!testRunner.FeatureContext.ContainsKey("driver"))
{
testRunner.FeatureContext.Add("driver", _driver);
}
// Start the scenario
scenarioMethod.Invoke(featureInstance, null);
// Copy back updated context values
FeatureContext.Fill(testRunner.FeatureContext);
}).Wait();
}
catch (Exception ex)
{
throw ex;
}
}