public void Execute(CommandLineArguments arguments) { var assemblyPath = arguments.AssemblyPath; var featurePattern = arguments.FeaturePattern; featureRunner.AddListener(new ConsoleWritingEventListener { ShowCurrentTimes = arguments.ShowCurrentTime, }); var filter = new TagFilter(arguments.TagsToInclude, arguments.TagsToExclude); var featuresToRun = featureFileFinder.Find(featurePattern) .SelectMany(fileName => gherkinParser.Parse(fileName, fileReader.Read(fileName, Encoding.UTF8)).Features) .Where(f => filter.IsSatisfiedBy(f.Tags)); Console.WriteLine("Found {0} features containing {1} executable scenarios", featuresToRun.Count(), featuresToRun.Sum(f => f.Scenarios.Count)); var actionStepsTypes = actionStepsFinder.FindTypesWithActionSteps(assemblyPath); var options = new RunnerOptions { Filter = filter, DruRun = arguments.DruRun, SuccessRequired = arguments.SuccessRequired, }; foreach (var feature in featuresToRun) { var featureResult = featureRunner.Run(feature, actionStepsTypes, options); if (options.SuccessRequired && !featureResult.Success) { break; } } }
FeatureResult ExecuteFeature(Feature feature, Type[] types, RunnerOptions options) { var featureResult = new FeatureResult(feature); var matcher = new StepMatcher(); var finder = new ActionStepFinder(); var steps = GetUniqueSteps(feature); var actionStepsClasses = finder.Find(types); var matches = MatchStepsToActionMethods(steps, actionStepsClasses, matcher); var executionObjects = GetExecutionObjects(matches); var filter = options.Filter; try { BeforeFeature(feature, executionObjects); foreach (var scenario in feature.Scenarios.SelectMany(s => s.GetExecutableScenarios()).Where(s => filter.IsSatisfiedBy(s.Tags))) { BeforeScenario(feature, scenario, executionObjects); var result = ExecuteScenario(scenario, feature, matches, executionObjects, options); featureResult.AddScenarioResult(result); AfterScenario(feature, scenario, result, executionObjects); if (options.SuccessRequired && !result.Success) { break; } } AfterFeature(feature, featureResult, executionObjects); } finally { CleanUpExecutionObjects(executionObjects); } return(featureResult); }
StepResult ExecuteStep(Step step, IEnumerable <FoundMatch> matches, IDictionary <Type, ActionStepsObjectHolder> executionObjects, RunnerOptions options) { var stepResult = new StepResult(step.Text); var stepToMatch = step; var method = matches.SingleOrDefault(m => m.StepMatch.Step.Matches(stepToMatch)); if (method == null) { stepResult.Result = Result.Pending; } else { try { var targetObject = executionObjects[method.RequiredType].GetInstance(); var parameters = GenerateParameterList(method.ActionStepMethod, method.StepMatch); var methodInfo = method.ActionStepMethod.MethodInfo; if (!options.DruRun) { methodInfo.Invoke(targetObject, parameters); } stepResult.Result = Result.Success; } catch (TargetInvocationException ex) { var innerException = ex.InnerException; if (innerException is FeatureExecutionException) { throw; } stepResult.Result = Result.Failed; stepResult.ErrorMessage = innerException.ToString(); } catch (Exception ex) { stepResult.Result = Result.Failed; stepResult.ErrorMessage = ex.ToString(); } } return(stepResult); }
public FeatureResult Run(Feature feature, Type[] types, RunnerOptions options) { return(ExecuteFeature(feature, types, options)); }
ScenarioResult ExecuteScenario(Scenario scenario, Feature feature, IEnumerable <FoundMatch> matches, Dictionary <Type, ActionStepsObjectHolder> executionObjects, RunnerOptions options) { var scenarioResult = new ScenarioResult(scenario.Headline); foreach (var step in feature.BackgroundSteps.Concat(scenario.Steps)) { BeforeStep(scenario, feature, step, executionObjects); var result = ExecuteStep(step, matches, executionObjects, options); scenarioResult.AddStepResult(result); AfterStep(scenario, feature, step, result, executionObjects); if (options.SuccessRequired && !result.Success) { break; } } return(scenarioResult); }