public override SpecFlowDocument GetDocument() { var parser = SpecFlowParserHelper.CreateParser(); var path = Path.Combine(SpecFlowProject.FeatureFilesFolder, RelativePath); using (var stream = File.OpenText(path)) { var content = stream.ReadToEnd(); return(ParseDocument(content, path, parser)); } }
public override SpecFlowDocument GetDocument() { var parser = SpecFlowParserHelper.CreateParser(); var assembly = Assembly.ReflectionOnlyLoadFrom(this.SpecFlowProject.AssemblyPath); using (var stream = assembly.GetManifestResourceStream(this.RelativePath)) using (var reader = new StreamReader(stream)) { var content = reader.ReadToEnd(); return(ParseDocument(content, null, parser)); } }
protected override bool FindTestsForType(ITestClass testClass, bool includeSourceInformation, IMessageBus messageBus, ITestFrameworkDiscoveryOptions discoveryOptions) { if (!IsSpecFlowTest(testClass)) { return(base.FindTestsForType(testClass, includeSourceInformation, messageBus, discoveryOptions)); } var featureTestClass = (SpecFlowFeatureTestClass)testClass; var gherkinDocument = featureTestClass.GetDocument(); if (gherkinDocument?.SpecFlowFeature != null) { featureTestClass.FeatureName = gherkinDocument.SpecFlowFeature.Name; var featureTags = gherkinDocument.SpecFlowFeature.Tags.GetTags().ToArray(); foreach (var scenarioDefinition in gherkinDocument.SpecFlowFeature.ScenarioDefinitions.Where(sd => !(sd is Background))) { var scenario = scenarioDefinition as Scenario; if (scenario != null) { var scenarioTestCase = new ScenarioTestCase(featureTestClass, scenario, featureTags); if (!messageBus.QueueMessage(new TestCaseDiscoveryMessage(scenarioTestCase))) { return(false); } } var scenarioOutline = scenarioDefinition as ScenarioOutline; if (scenarioOutline != null) { foreach (var example in scenarioOutline.Examples) { foreach (var exampleRow in example.TableBody) { var parameters = SpecFlowParserHelper.GetScenarioOutlineParameters(example, exampleRow); var scenarioOutlineTestCase = new ScenarioTestCase(featureTestClass, scenarioOutline, featureTags, parameters, SpecFlowParserHelper.GetExampleRowId(scenarioOutline, exampleRow), exampleRow.Location); if (!messageBus.QueueMessage(new TestCaseDiscoveryMessage(scenarioOutlineTestCase))) { return(false); } } } } } } return(true); }
protected override async Task <RunSummary> RunTestAsync() { var test = new XunitTest(TestCase, TestCase.DisplayName); //TODO: this is a pickle, we could use the Compiler/Pickle interfaces from the Gherkin parser var summary = new RunSummary() { Total = 1 }; string output = ""; var gherkinDocument = await this.TestCase.FeatureTypeInfo.GetDocumentAsync(); Scenario scenario = null; if (gherkinDocument.SpecFlowFeature != null) { if (TestCase.IsScenarioOutline) { var scenarioOutline = gherkinDocument.SpecFlowFeature.ScenarioDefinitions.OfType <ScenarioOutline>().FirstOrDefault(s => s.Name == TestCase.Name); if (scenarioOutline != null && SpecFlowParserHelper.GetExampleRowById(scenarioOutline, TestCase.ExampleId, out var example, out var exampleRow)) { scenario = SpecFlowParserHelper.CreateScenario(scenarioOutline, example, exampleRow); } } else { scenario = gherkinDocument.SpecFlowFeature.ScenarioDefinitions.OfType <Scenario>().FirstOrDefault(s => s.Name == TestCase.Name); } } string skipReason = null; if (scenario == null) { skipReason = $"Unable to find Scenario: {TestCase.DisplayName}"; } else if (gherkinDocument.SpecFlowFeature.Tags.GetTags().Concat(scenario.Tags.GetTags()).Contains("ignore")) { skipReason = "Ignored"; } if (skipReason != null) { summary.Skipped++; if (!MessageBus.QueueMessage(new TestSkipped(test, skipReason))) { CancellationTokenSource.Cancel(); } } else { var aggregator = new ExceptionAggregator(Aggregator); if (!aggregator.HasExceptions) { aggregator.Run(() => { var stopwatch = Stopwatch.StartNew(); testOutputHelper.Initialize(MessageBus, test); try { RunScenario(gherkinDocument, scenario); } finally { stopwatch.Stop(); summary.Time = (decimal)stopwatch.Elapsed.TotalSeconds; output = testOutputHelper.Output; testOutputHelper.Uninitialize(); } } ); } var exception = aggregator.ToException(); TestResultMessage testResult; if (exception == null) { testResult = new TestPassed(test, summary.Time, output); } else { testResult = new TestFailed(test, summary.Time, output, exception); summary.Failed++; } if (!CancellationTokenSource.IsCancellationRequested) { if (!MessageBus.QueueMessage(testResult)) { CancellationTokenSource.Cancel(); } } } if (!MessageBus.QueueMessage(new TestFinished(test, summary.Time, output))) { CancellationTokenSource.Cancel(); } return(summary); }
protected override async Task <RunSummary> RunTestAsync() { var test = new XunitTest(TestCase, TestCase.DisplayName); //TODO: this is a pickle, we could use the Compiler/Pickle interfaces from the Gherkin parser var summary = new RunSummary() { Total = 1 }; var output = new StringBuilder(); var gherkinDocument = await SpecFlowParserHelper.ParseSpecFlowDocumentAsync(TestCase.FeatureFile.FeatureFilePath); Scenario scenario = null; if (gherkinDocument.SpecFlowFeature != null) { if (TestCase.IsScenarioOutline) { var scenarioOutline = gherkinDocument.SpecFlowFeature.ScenarioDefinitions.OfType <ScenarioOutline>().FirstOrDefault(s => s.Name == TestCase.Name); Examples example = null; Gherkin.Ast.TableRow exampleRow = null; if (scenarioOutline != null && SpecFlowParserHelper.GetExampleRowById(scenarioOutline, TestCase.ExampleId, out example, out exampleRow)) { scenario = SpecFlowParserHelper.CreateScenario(scenarioOutline, example, exampleRow); } } else { scenario = gherkinDocument.SpecFlowFeature.ScenarioDefinitions.OfType <Scenario>().FirstOrDefault(s => s.Name == TestCase.Name); } } string skipReason = null; if (scenario == null) { skipReason = $"Unable to find Scenario: {TestCase.DisplayName}"; } else if (gherkinDocument.SpecFlowFeature.Tags.GetTags().Concat(scenario.Tags.GetTags()).Contains("ignore")) { skipReason = "Ignored"; } if (skipReason != null) { summary.Skipped++; if (!MessageBus.QueueMessage(new TestSkipped(test, skipReason))) { CancellationTokenSource.Cancel(); } } else { var aggregator = new ExceptionAggregator(Aggregator); if (!aggregator.HasExceptions) { aggregator.Run(() => RunScenario(gherkinDocument, scenario, output)); } var exception = aggregator.ToException(); TestResultMessage testResult; if (exception == null) { testResult = new TestPassed(test, summary.Time, output.ToString()); } else { testResult = new TestFailed(test, summary.Time, output.ToString(), exception); summary.Failed++; } if (!CancellationTokenSource.IsCancellationRequested) { if (!MessageBus.QueueMessage(testResult)) { CancellationTokenSource.Cancel(); } } } if (!MessageBus.QueueMessage(new TestFinished(test, summary.Time, output.ToString()))) { CancellationTokenSource.Cancel(); } return(summary); }