public List <Pickle> Compile(GherkinDocument gherkinDocument) { var pickles = new List <Pickle>(); Feature feature = gherkinDocument.Feature; if (feature == null) { return(pickles); } var featureTags = feature.Tags; var backgroundSteps = new PickleStep[0]; foreach (var stepsContainer in feature.Children) { if (stepsContainer is Background) { backgroundSteps = PickleSteps(stepsContainer); } else { var scenario = (Scenario)stepsContainer; if (!scenario.Examples.Any()) { CompileScenario(pickles, backgroundSteps, scenario, featureTags, feature.Language); } else { CompileScenarioOutline(pickles, backgroundSteps, scenario, featureTags, feature.Language); } } } return(pickles); }
public IEnumerable <IEvent> iterable(SourceEvent sourceEvent) { List <IEvent> events = new List <IEvent> (); try { GherkinDocument gherkinDocument = parser.Parse(new StringReader(sourceEvent.data)); if (printSource) { events.Add(sourceEvent); } if (printAst) { events.Add(new GherkinDocumentEvent(sourceEvent.uri, gherkinDocument)); } if (printPickles) { List <Pickle> pickles = compiler.Compile(gherkinDocument); foreach (Pickle pickle in pickles) { events.Add(new PickleEvent(sourceEvent.uri, pickle)); } } } catch (CompositeParserException e) { foreach (ParserException error in e.Errors) { addErrorAttachment(events, error, sourceEvent.uri); } } catch (ParserException e) { addErrorAttachment(events, e, sourceEvent.uri); } return(events); }
public List <Pickle> Compile(GherkinDocument gherkinDocument) { var pickles = new List <Pickle>(); Feature feature = gherkinDocument.Feature; if (feature == null) { return(pickles); } var featureTags = feature.Tags; var backgroundSteps = new PickleStep[0]; foreach (var scenarioDefinition in feature.Children) { if (scenarioDefinition is Background) { backgroundSteps = PickleSteps(scenarioDefinition); } else if (scenarioDefinition is Scenario) { CompileScenario(pickles, backgroundSteps, (Scenario)scenarioDefinition, featureTags, feature.Language); } else { CompileScenarioOutline(pickles, backgroundSteps, (ScenarioOutline)scenarioDefinition, featureTags, feature.Language); } } return(pickles); }
public IEnumerable <IEvent> iterable(SourceEvent sourceEvent) { List <IEvent> events = new List <IEvent> (); try { GherkinDocument gherkinDocument = parser.Parse(new StringReader(sourceEvent.data)); if (printSource) { events.Add(sourceEvent); } if (printAst) { events.Add(new GherkinDocumentEvent(sourceEvent.uri, gherkinDocument)); } if (printPickles) { throw new NotSupportedException("Gherkin.NET doesn't have a pickle compiler yet"); } } catch (CompositeParserException e) { foreach (ParserException error in e.Errors) { addErrorAttachment(events, error, sourceEvent.uri); } } catch (ParserException e) { addErrorAttachment(events, e, sourceEvent.uri); } return(events); }
private IReadOnlyCollection <Comment> ConvertComments(GherkinDocument gherkinDocument) { return(gherkinDocument.Comments.Select(c => new Comment() { Text = c.Text, Location = ConvertLocation(c.Location) }).ToReadOnlyCollection()); }
public GherkinDocumentEventArgs ConvertGherkinDocumentToEventArgs(GherkinDocument gherkinDocument, string sourceEventUri) { return(new GherkinDocumentEventArgs() { Uri = sourceEventUri, Feature = ConvertFeature(gherkinDocument), Comments = ConvertComments(gherkinDocument) }); }
public void FeatureSetup(GherkinDocument gherkinDocument) { Debug.Assert(gherkinDocument.Feature != null); var feature = gherkinDocument.Feature; var assembly = Assembly.LoadFrom(TestCase.FeatureTypeInfo.SpecFlowProject.AssemblyPath); testRunner = TestRunnerManager.GetTestRunner(assembly); var featureInfo = new FeatureInfo(GetFeatureCulture(feature.Language), feature.Name, feature.Description, ProgrammingLanguage.CSharp, feature.Tags.GetTags().ToArray()); testRunner.OnFeatureStart(featureInfo); }
public List <Pickle> Compile(GherkinDocument gherkinDocument) { var pickles = new List <Pickle>(); var feature = gherkinDocument.Feature; if (feature == null) { return(pickles); } var language = feature.Language; var tags = feature.Tags; BuildFeature(pickles, language, tags, Enumerable.Empty <PickleStep>, feature.Children, gherkinDocument.Uri); return(pickles); }
public GeneratedFiles GenCucumberTestCode(TextReader reader, string outputPath) { try { GherkinDocument gherkinDocument = ParseFeature(reader); GeneratedFiles generated_file_names = GenerateBDDTestCodes(gherkinDocument.Feature, outputPath); EventAggregator <StatusChangedArg> .Instance.Publish(this, new StatusChangedArg("Completed C++ test code")); return(generated_file_names); } catch { EventAggregator <StatusChangedArg> .Instance.Publish(this, new StatusChangedArg("Error")); throw; } }
private void GenerateHtmlForParsedFeature(GherkinDocument document, SbeFeature feature, StringBuilder sb) { foreach (var child in document.Feature.Children) { if (child is Background) { BackgroundHtml(child as Background, sb); } else if (child is ScenarioDefinition) { ScenarioHtml(child as ScenarioDefinition, sb, feature.Scenarios); } else { throw new NotSupportedException($"Type {child.GetType().FullName} is not a supported child of a feature."); } } }
private string FeatureHtml(GherkinDocument document, SbeFeature feature) { var sb = new StringBuilder(); sb.AppendLine("<div class=\"feature\">"); TagsHtml(sb, document.Feature.Tags); sb.AppendLine($@"<table class=""feature-title""><tr><td>{GenerateStatusImageTag(feature.GetOutcome())}</td> <td class=""text"">{document.Feature.Keyword}: {HtmlEncode(document.Feature.Name)}</td></tr></table>"); sb.AppendLine($"<p>{AddLineBreaks(HtmlEncode(document.Feature.Description))}</p>"); GenerateHtmlForParsedFeature(document, feature, sb); sb.AppendLine("</div>"); return(sb.ToString()); }
private Feature ConvertFeature(GherkinDocument gherkinDocument) { var feature = gherkinDocument.Feature; if (feature == null) { return(null); } return(new Feature() { Name = feature.Name == string.Empty ? null : feature.Name, Keyword = feature.Keyword, Language = feature.Language, Location = ConvertLocation(feature.Location), Children = feature.Children.Select(ConvertToChildren).ToReadOnlyCollection() }); }
public List <Pickle> Compile(GherkinDocument gherkinDocument) { var pickles = new List <Pickle>(); Feature feature = gherkinDocument.Feature; if (feature == null) { return(pickles); } var language = feature.Language; var tags = feature.Tags; var backgroundSteps = new PickleStep[0]; Build(pickles, language, tags, backgroundSteps, feature); return(pickles); }
protected FeatureContext(Dill dillInstance, string featureFileName) { _relishInstance = dillInstance; string featureFile = string.Empty; if (dillInstance.FeatureLoaderType == FeatureLoaderType.EmbeddedResource) { featureFile = LoadResource(featureFileName); } if (dillInstance.FeatureLoaderType == FeatureLoaderType.File) { featureFile = LoadFile(featureFileName); } using (var sr = new StringReader(featureFile)) { var parser = new Parser(); _gherkinDocument = parser.Parse(sr); } }
public IEnumerable <IEvent> Iterable(Sources sourceEvent) { List <IEvent> events = new List <IEvent>(); try { GherkinDocument gherkinDocument = _parser.Parse(new StringReader(sourceEvent.Data)); if (_printSource) { events.Add(_sourceEventConverter.Convert(sourceEvent)); } if (_printAst) { events.Add(new GherkinDocumentEvent(_astEventConverter.ConvertGherkinDocumentToEventArgs(gherkinDocument, sourceEvent.Uri))); } if (_printPickles) { List <Pickle> pickles = _compiler.Compile(gherkinDocument); foreach (Pickle pickle in pickles) { events.Add(new PickleEvent(_pickleEventConverter.Convert(pickle, sourceEvent.Uri))); } } } catch (CompositeParserException e) { foreach (ParserException error in e.Errors) { addErrorAttachment(events, error, sourceEvent.Uri); } } catch (ParserException e) { addErrorAttachment(events, e, sourceEvent.Uri); } return(events); }
private Feature ConvertFeature(GherkinDocument gherkinDocument) { var feature = gherkinDocument.Feature; if (feature == null) { return(null); } var children = feature.Children.Select(ConvertToChildren).ToReadOnlyCollection(); var tags = feature.Tags.Select(ConvertTag).ToReadOnlyCollection(); return(new Feature() { Name = feature.Name == string.Empty ? null : feature.Name, Description = feature.Description == string.Empty ? null : feature.Description, Keyword = feature.Keyword, Language = feature.Language, Location = ConvertLocation(feature.Location), Children = children, Tags = tags }); }
public void CreateScenarios(BusinessFlow BF) { string FileName = string.Empty; if (BF.ExternalID != null) { FileName = BF.ExternalID.Replace(@"~", WorkSpace.Instance.Solution.Folder); } if (!System.IO.File.Exists(FileName)) { // General Reporter.ToUser(eUserMsgKey.GherkinFileNotFound, FileName); return; } Parser parser = new Parser(); GherkinDocument gherkinDocument = parser.Parse(FileName); mBizFlow = BF; ClearGeneretedActivites(mBizFlow); ClearOptimizedScenariosVariables(mBizFlow); //Add Tags to BF foreach (var t in gherkinDocument.Feature.Tags) { Guid TagGuid = GetOrCreateTagInSolution(t.Name); mBizFlow.Tags.Add(TagGuid); } foreach (Gherkin.Ast.ScenarioDefinition sc in gherkinDocument.Feature.Children) { IEnumerable <Examples> examples = null; // In case of Scenario Outline we need to generate new BF per each line in the table of examples if (sc.Keyword == "Scenario Outline") { ScenarioOutline so = (ScenarioOutline)sc; examples = so.Examples; } // Create new BF per each scenario if (examples == null) { CreateScenario(sc); } else { int i = 0; ValuesDict = new Dictionary <string, List <OptionalValue> >(); //TODO: handle case of more than one example table - check what is Gherking expected todo: all combinations!!?? foreach (Examples x in examples) { foreach (Gherkin.Ast.TableRow tr in x.TableBody) { i++; ActivitiesGroup AG = CreateScenario(sc, i); // Now the we have the flow created with activities, we update the activities var replacing <param> with value from table var activities = from z in BF.Activities where z.ActivitiesGroupID == AG.Name select z; foreach (Activity a in activities) { while (true) { string ColName = General.GetStringBetween(a.ActivityName, "<", ">"); if (string.IsNullOrEmpty(ColName)) { break; } string val = GetExampleValue(x.TableHeader, tr, ColName); a.ActivityName = a.ActivityName.Replace("<" + ColName + ">", "\"" + val + "\""); VariableBase v = a.Variables.Where(y => y.Name == ColName).FirstOrDefault(); OptionalValue ov = new OptionalValue(val); if (ValuesDict.ContainsKey(ColName)) { ValuesDict[ColName].Add(ov); } else { List <OptionalValue> newList = new List <OptionalValue>(); newList.Add(ov); ValuesDict.Add(ColName, newList); } ((VariableSelectionList)v).OptionalValuesList.Add(ov); ((VariableSelectionList)v).SelectedValue = val; } } } } foreach (Activity a in BF.Activities) { foreach (VariableBase vb in a.Variables) { if (vb is VariableSelectionList) { if (ValuesDict.ContainsKey(vb.Name)) { foreach (OptionalValue ov in ValuesDict[vb.Name]) { OptionalValue ExistedOV = ((VariableSelectionList)vb).OptionalValuesList.Where(y => y.Value == ov.Value).FirstOrDefault(); if (ExistedOV == null) { ((VariableSelectionList)vb).OptionalValuesList.Add(ov); } } } } } } } } if (!string.IsNullOrEmpty(NotFoundItems)) { Reporter.ToUser(eUserMsgKey.GherkinColumnNotExist, NotFoundItems); } }
public async Task <GherkinParseResult> Parse(string specificationId, string gherkin, BuildProject buildProject) { Guard.IsNullOrWhiteSpace(specificationId, nameof(specificationId)); Guard.IsNullOrWhiteSpace(gherkin, nameof(gherkin)); Guard.ArgumentNotNull(buildProject, nameof(buildProject)); buildProject.Build.Assembly = await _calculationsRepository.GetAssemblyBySpecificationId(specificationId); GherkinParseResult result = new GherkinParseResult(); Parser parser = new Parser(); try { StringBuilder builder = new StringBuilder(); builder.AppendLine("Feature: Feature Wrapper"); builder.AppendLine(" Scenario: Scenario Wrapper"); builder.Append(gherkin); using (StringReader reader = new StringReader(builder.ToString())) { GherkinDocument document = null; try { document = parser.Parse(reader); } catch (InvalidOperationException ex) { string buildProjectId = buildProject.Id; _logger.Error(ex, $"Gherkin parser error for build project {{buildProjectId}}: {builder.ToString()}", buildProjectId); throw; } if (document.Feature?.Children != null) { foreach (ScenarioDefinition scenario in document.Feature?.Children) { if (!scenario.Steps.IsNullOrEmpty()) { foreach (Step step in scenario.Steps) { IEnumerable <KeyValuePair <StepType, string> > expression = stepExpressions.Where(m => Regex.IsMatch(step.Text, m.Value, RegexOptions.IgnoreCase)); if (expression.Any()) { IStepParser stepParser = _stepParserFactory.GetStepParser(expression.First().Key); if (stepParser == null) { result.AddError("The supplied gherkin could not be parsed", step.Location.Line, step.Location.Column); } else { await stepParser.Parse(step, expression.First().Value, result, buildProject); } } else { result.AddError("The supplied gherkin could not be parsed", step.Location.Line, step.Location.Column); } string keyword = step.Keyword?.ToLowerInvariant().Trim(); } } else { result.AddError("The supplied gherkin could not be parsed", 0, 0); } } } } } catch (CompositeParserException exception) { foreach (ParserException error in exception.Errors) { result.AddError(error.Message, error.Location.Line, error.Location.Column); } } return(result); }
public List <Pickle> GetPickles(GherkinDocument document) { return(new Compiler().Compile(document)); }
public GherkinDocumentEvent(string uri, GherkinDocument document) { this.uri = uri; this.document = document; }
internal Feature(GherkinDocument document, IEnumerable <Scenario> scenarios) => (Document, Scenarios) = (document, scenarios);
public FeatureFile(GherkinDocument gherkinDocument) { GherkinDocument = gherkinDocument ?? throw new System.ArgumentNullException(nameof(gherkinDocument)); }
protected static TestFeature DiscoverPesterFeatures(string source, IMessageLogger logger) { if (!File.Exists(source)) { return(null); } Gherkin.Parser parser = new Gherkin.Parser(); GherkinDocument document = parser.Parse(source); TestFeature feature = new TestFeature { Name = Path.GetFileNameWithoutExtension(source), Path = source, Document = document }; foreach (ScenarioDefinition scenario in document.Feature.Children) { if (scenario is ScenarioOutline outline) { foreach (Examples example in outline.Examples) { TestScenario testScenario = new TestScenario() { Name = $"{scenario.Name}\n Examples:{example.Name}", Path = source, Scenario = scenario }; feature.Scenarios.Add(testScenario); foreach (TableRow row in example.TableBody) { foreach (Step step in scenario.Steps) { TestStep testStep = new TestStep() { Name = step.Text, Path = source, Step = step }; testScenario.Steps.Add(testStep); } } } } else { TestScenario testScenario = new TestScenario() { Name = scenario.Name, Path = source, Scenario = scenario }; feature.Scenarios.Add(testScenario); foreach (Step step in scenario.Steps) { TestStep testStep = new TestStep() { Name = step.Text, Path = source, Step = step }; testScenario.Steps.Add(testStep); } } } if (feature.Scenarios.Count == 0) { return(null); } return(feature); }