How to use Background method of Gherkin.Ast.Background class

Best Gherkin-dotnet code snippet using Gherkin.Ast.Background.Background

FeatureClassTests.cs

Source:FeatureClassTests.cs Github

copy

Full Screen

...54 await Task.CompletedTask;55 }56 }57 [Fact]58 public void ExtractScenario_Extracts_Scenario_Without_Background()59 {60 //arrange.61 var scenarioName = "some scenario name 123";62 var featureInstance = new FeatureWithMatchingScenarioStepsToExtract();63 var sut = FeatureClass.FromFeatureInstance(featureInstance);64 var gherkinScenario = CreateGherkinDocument(scenarioName,65 new string[]66 {67 "Given " + FeatureWithMatchingScenarioStepsToExtract.ScenarioStep1Text.Replace(@"(\d+)", "12", StringComparison.InvariantCultureIgnoreCase),68 "And " + FeatureWithMatchingScenarioStepsToExtract.ScenarioStep2Text.Replace(@"(\d+)", "15", StringComparison.InvariantCultureIgnoreCase),69 "When " + FeatureWithMatchingScenarioStepsToExtract.ScenarioStep3Text,70 "Then " + FeatureWithMatchingScenarioStepsToExtract.ScenarioStep4Text.Replace(@"(\d+)", "27", StringComparison.InvariantCultureIgnoreCase)71 }).Feature.Children.First() as Gherkin.Ast.Scenario;72 //act.73 var scenario = sut.ExtractScenario(gherkinScenario);74 //assert.75 Assert.NotNull(scenario);76 } 77 private static Gherkin.Ast.GherkinDocument CreateGherkinDocument(78 string scenario,79 string[] steps,80 Gherkin.Ast.StepArgument stepArgument = null,81 string[] backgroundSteps = null)82 {83 var definitions = new List<global::Gherkin.Ast.ScenarioDefinition>84 {85 new Gherkin.Ast.Scenario(86 new Gherkin.Ast.Tag[0],87 null,88 null,89 scenario,90 null,91 steps.Select(s =>92 {93 var spaceIndex = s.IndexOf(' ');94 return new Gherkin.Ast.Step(95 null,96 s.Substring(0, spaceIndex).Trim(),97 s.Substring(spaceIndex).Trim(),98 stepArgument);99 }).ToArray())100 };101 if(backgroundSteps != null)102 {103 definitions.Add(104 new Gherkin.Ast.Background(105 null,106 null,107 "background",108 null,109 backgroundSteps.Select(s =>110 {111 var spaceIndex = s.IndexOf(' ');112 return new Gherkin.Ast.Step(113 null,114 s.Substring(0, spaceIndex).Trim(),115 s.Substring(spaceIndex).Trim(),116 stepArgument);117 }).ToArray()));118 }119 return new Gherkin.Ast.GherkinDocument(120 new Gherkin.Ast.Feature(new Gherkin.Ast.Tag[0], null, null, null, null, null, definitions.ToArray()),121 new Gherkin.Ast.Comment[0]);122 }123 private sealed class FeatureWithMatchingScenarioStepsToExtract : Feature124 {125 public List<KeyValuePair<string, object[]>> CallStack { get; } = new List<KeyValuePair<string, object[]>>();126 [Given("a background step")]127 public void GivenBackground()128 {129 CallStack.Add(new KeyValuePair<string, object[]>(nameof(GivenBackground), null));130 }131 [Given("Non matching given")]132 public void NonMatchingStep1_before()133 {134 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep1_before), null));135 }136 public const string ScenarioStep1Text = @"I chose (\d+) as first number";137 [Given(ScenarioStep1Text)]138 public void ScenarioStep1(int firstNumber)139 {140 CallStack.Add(new KeyValuePair<string, object[]>(nameof(ScenarioStep1), new object[] { firstNumber }));141 }142 [Given("Non matching given")]143 public void NonMatchingStep1_after()...

Full Screen

Full Screen

AstBuilder.cs

Source:AstBuilder.cs Github

copy

Full Screen

...77 {78 var rows = GetTableRows(node);79 return CreateDataTable(rows, node);80 }81 case RuleType.Background:82 {83 var backgroundLine = node.GetToken(TokenType.BackgroundLine);84 var description = GetDescription(node);85 var steps = GetSteps(node);86 return CreateBackground(GetLocation(backgroundLine), backgroundLine.MatchedKeyword, backgroundLine.MatchedText, description, steps, node);87 }88 case RuleType.ScenarioDefinition:89 {90 var tags = GetTags(node);9192 var scenarioNode = node.GetSingle<AstNode>(RuleType.Scenario);93 var scenarioLine = scenarioNode.GetToken(TokenType.ScenarioLine);9495 var description = GetDescription(scenarioNode);96 var steps = GetSteps(scenarioNode);97 var examples = scenarioNode.GetItems<Examples>(RuleType.ExamplesDefinition).ToArray();98 return CreateScenario(tags, GetLocation(scenarioLine), scenarioLine.MatchedKeyword, scenarioLine.MatchedText, description, steps, examples, node);99 }100 case RuleType.ExamplesDefinition:101 {102 var tags = GetTags(node);103 var examplesNode = node.GetSingle<AstNode>(RuleType.Examples);104 var examplesLine = examplesNode.GetToken(TokenType.ExamplesLine);105 var description = GetDescription(examplesNode);106107 var allRows = examplesNode.GetSingle<TableRow[]>(RuleType.ExamplesTable);108 var header = allRows != null ? allRows.First() : null;109 var rows = allRows != null ? allRows.Skip(1).ToArray() : null;110 return CreateExamples(tags, GetLocation(examplesLine), examplesLine.MatchedKeyword, examplesLine.MatchedText, description, header, rows, node);111 }112 case RuleType.ExamplesTable:113 {114 return GetTableRows(node);115 }116 case RuleType.Description:117 {118 var lineTokens = node.GetTokens(TokenType.Other);119120 // Trim trailing empty lines121 lineTokens = lineTokens.Reverse().SkipWhile(t => string.IsNullOrWhiteSpace(t.MatchedText)).Reverse();122123 return string.Join(Environment.NewLine, lineTokens.Select(lt => lt.MatchedText));124 }125 case RuleType.Feature:126 {127 var header = node.GetSingle<AstNode>(RuleType.FeatureHeader);128 if(header == null) return null;129 var tags = GetTags(header);130 var featureLine = header.GetToken(TokenType.FeatureLine);131 if(featureLine == null) return null;132 var children = new List<IHasLocation> ();133 var background = node.GetSingle<Background>(RuleType.Background);134 if (background != null) 135 {136 children.Add (background);137 }138 var childrenEnumerable = children.Concat(node.GetItems<IHasLocation>(RuleType.ScenarioDefinition))139 .Concat(node.GetItems<IHasLocation>(RuleType.Rule));140 var description = GetDescription(header);141 if(featureLine.MatchedGherkinDialect == null) return null;142 var language = featureLine.MatchedGherkinDialect.Language;143144 return CreateFeature(tags, GetLocation(featureLine), language, featureLine.MatchedKeyword, featureLine.MatchedText, description, childrenEnumerable.ToArray(), node);145 }146 case RuleType.Rule:147 {148 var header = node.GetSingle<AstNode>(RuleType.RuleHeader);149 if (header == null) return null;150 var ruleLine = header.GetToken(TokenType.RuleLine);151 if (ruleLine == null) return null;152 var children = new List<IHasLocation>();153 var background = node.GetSingle<Background>(RuleType.Background);154 if (background != null)155 {156 children.Add(background);157 }158 var childrenEnumerable = children.Concat(node.GetItems<IHasLocation>(RuleType.ScenarioDefinition));159 var description = GetDescription(header);160 if (ruleLine.MatchedGherkinDialect == null) return null;161 var language = ruleLine.MatchedGherkinDialect.Language;162163 return CreateRule(GetLocation(ruleLine), ruleLine.MatchedKeyword, ruleLine.MatchedText, description, childrenEnumerable.ToArray(), node);164 }165 case RuleType.GherkinDocument:166 {167 var feature = node.GetSingle<Feature>(RuleType.Feature);168169 return CreateGherkinDocument(feature, comments.ToArray(), node);170 }171 }172173 return node;174 }175176 protected virtual Background CreateBackground(Location location, string keyword, string name, string description, Step[] steps, AstNode node)177 {178 return new Background(location, keyword, name, description, steps);179 }180181 protected virtual DataTable CreateDataTable(TableRow[] rows, AstNode node)182 {183 return new DataTable(rows);184 }185186 protected virtual Comment CreateComment(Location location, string text)187 {188 return new Comment(location, text);189 }190191 protected virtual Examples CreateExamples(Tag[] tags, Location location, string keyword, string name, string description, TableRow header, TableRow[] body, AstNode node)192 { ...

Full Screen

Full Screen

AstMessagesConverter.cs

Source:AstMessagesConverter.cs Github

copy

Full Screen

2using System.Collections.Generic;3using System.Linq;4using Gherkin.Ast;5using Gherkin.CucumberMessages.Types;6using Background = Gherkin.CucumberMessages.Types.Background;7using Comment = Gherkin.CucumberMessages.Types.Comment;8using Examples = Gherkin.CucumberMessages.Types.Examples;9using Feature = Gherkin.CucumberMessages.Types.Feature;10using Location = Gherkin.CucumberMessages.Types.Location;11using Rule = Gherkin.CucumberMessages.Types.Rule;12using Step = Gherkin.CucumberMessages.Types.Step;13using DataTable = Gherkin.CucumberMessages.Types.DataTable;14using DocString = Gherkin.CucumberMessages.Types.DocString;15using GherkinDocument = Gherkin.CucumberMessages.Types.GherkinDocument;16using Scenario = Gherkin.CucumberMessages.Types.Scenario;17using TableCell = Gherkin.CucumberMessages.Types.TableCell;18using TableRow = Gherkin.CucumberMessages.Types.TableRow;19using Tag = Gherkin.CucumberMessages.Types.Tag;20namespace Gherkin.CucumberMessages21{22 public class AstMessagesConverter23 {24 private readonly IIdGenerator _idGenerator;25 public AstMessagesConverter(IIdGenerator idGenerator)26 {27 _idGenerator = idGenerator;28 }29 public GherkinDocument ConvertGherkinDocumentToEventArgs(Ast.GherkinDocument gherkinDocument, string sourceEventUri)30 {31 return new GherkinDocument()32 {33 Uri = sourceEventUri,34 Feature = ConvertFeature(gherkinDocument),35 Comments = ConvertComments(gherkinDocument)36 };37 }38 private IReadOnlyCollection<Comment> ConvertComments(Ast.GherkinDocument gherkinDocument)39 {40 return gherkinDocument.Comments.Select(c =>41 new Comment()42 {43 Text = c.Text,44 Location = ConvertLocation(c.Location)45 }).ToReadOnlyCollection();46 }47 private Feature ConvertFeature(Ast.GherkinDocument gherkinDocument)48 {49 var feature = gherkinDocument.Feature;50 if (feature == null)51 {52 return null;53 }54 var children = feature.Children.Select(ConvertToFeatureChild).ToReadOnlyCollection();55 var tags = feature.Tags.Select(ConvertTag).ToReadOnlyCollection();56 return new Feature()57 {58 Name = CucumberMessagesDefaults.UseDefault(feature.Name, CucumberMessagesDefaults.DefaultName),59 Description = CucumberMessagesDefaults.UseDefault(feature.Description, CucumberMessagesDefaults.DefaultDescription),60 Keyword = feature.Keyword,61 Language = feature.Language,62 Location = ConvertLocation(feature.Location),63 Children = children,64 Tags = tags65 };66 }67 private static Location ConvertLocation(Ast.Location location)68 {69 return new Location(location.Column, location.Line);70 }71 private FeatureChild ConvertToFeatureChild(IHasLocation hasLocation)72 {73 var tuple = ConvertToChild(hasLocation);74 return new FeatureChild(tuple.Item3, tuple.Item1, tuple.Item2);75 }76 77 private RuleChild ConvertToRuleChild(IHasLocation hasLocation)78 {79 var tuple = ConvertToChild(hasLocation);80 return new RuleChild(tuple.Item1, tuple.Item3);81 }82 83 private Tuple<Background, Rule, Scenario> ConvertToChild(IHasLocation hasLocation)84 {85 switch (hasLocation)86 {87 case Gherkin.Ast.Background background:88 var backgroundSteps = background.Steps.Select(ConvertStep).ToList();89 return new Tuple<Background, Rule, Scenario>(new Background90 {91 Id = _idGenerator.GetNewId(),92 Location = ConvertLocation(background.Location),93 Name = CucumberMessagesDefaults.UseDefault(background.Name, CucumberMessagesDefaults.DefaultName),94 Description = CucumberMessagesDefaults.UseDefault(background.Description, CucumberMessagesDefaults.DefaultDescription),95 Keyword = background.Keyword,96 Steps = backgroundSteps97 }, null, null);98 case Ast.Scenario scenario:99 var steps = scenario.Steps.Select(ConvertStep).ToList();100 var examples = scenario.Examples.Select(ConvertExamples).ToReadOnlyCollection();101 var tags = scenario.Tags.Select(ConvertTag).ToReadOnlyCollection();102 return new Tuple<Background, Rule, Scenario>(null, null, new Scenario()103 {104 Id = _idGenerator.GetNewId(),105 Keyword = scenario.Keyword,106 Location = ConvertLocation(scenario.Location),107 Name = CucumberMessagesDefaults.UseDefault(scenario.Name, CucumberMessagesDefaults.DefaultName),108 Description = CucumberMessagesDefaults.UseDefault(scenario.Description, CucumberMessagesDefaults.DefaultDescription),109 Steps = steps,110 Examples = examples,111 Tags = tags112 });113 case Ast.Rule rule:114 {115 var ruleChildren = rule.Children.Select(ConvertToRuleChild).ToReadOnlyCollection();116 var ruleTags = rule.Tags.Select(ConvertTag).ToReadOnlyCollection();117 return new Tuple<Background, Rule, Scenario>(null, new Rule118 {119 Id = _idGenerator.GetNewId(),120 Name = CucumberMessagesDefaults.UseDefault(rule.Name, CucumberMessagesDefaults.DefaultName),121 Description = CucumberMessagesDefaults.UseDefault(rule.Description, CucumberMessagesDefaults.DefaultDescription),122 Keyword = rule.Keyword,123 Children = ruleChildren,124 Location = ConvertLocation(rule.Location),125 Tags = ruleTags126 }, null);127 }128 default:129 throw new NotImplementedException();130 }131 }...

Full Screen

Full Screen

CompatibleAstConverter.cs

Source:CompatibleAstConverter.cs Github

copy

Full Screen

2using System.Collections.Generic;3using System.Linq;4using Gherkin.Ast;5using TechTalk.SpecFlow.Parser.SyntaxElements;6using Background = TechTalk.SpecFlow.Parser.SyntaxElements.Background;7using Comment = TechTalk.SpecFlow.Parser.SyntaxElements.Comment;8using Examples = TechTalk.SpecFlow.Parser.SyntaxElements.Examples;9using Feature = TechTalk.SpecFlow.Parser.SyntaxElements.Feature;10using Scenario = TechTalk.SpecFlow.Parser.SyntaxElements.Scenario;11using ScenarioOutline = TechTalk.SpecFlow.Parser.SyntaxElements.ScenarioOutline;12using Tag = TechTalk.SpecFlow.Parser.SyntaxElements.Tag;13namespace TechTalk.SpecFlow.Parser.Compatibility14{15 public class CompatibleAstConverter16 {17 public static Feature ConvertToCompatibleFeature(SpecFlowDocument specFlowDocument)18 {19 var specFlowFeature = specFlowDocument.SpecFlowFeature;20 return new Feature(specFlowFeature.Keyword, specFlowFeature.Name, 21 ConvertToCompatibleTags(specFlowFeature.Tags),22 specFlowFeature.Description, 23 ConvertToCompatibleBackground(specFlowFeature.Background), 24 ConvertToCompatibleScenarios(specFlowFeature.ScenarioDefinitions), 25 ConvertToCompatibleComments(specFlowDocument.Comments))26 {27 FilePosition = ConvertToCompatibleFilePosition(specFlowFeature.Location),28 Language = specFlowFeature.Language,29 SourceFile = specFlowDocument.SourceFilePath30 };31 }32 private static Comment[] ConvertToCompatibleComments(IEnumerable<global::Gherkin.Ast.Comment> comments)33 {34 return comments.Select(ConvertToCompatibleComment).Where(c => c != null).ToArray();35 }36 private static Comment ConvertToCompatibleComment(global::Gherkin.Ast.Comment c)37 {38 var trimmedText = c.Text.TrimStart('#', ' ', '\t');39 if (trimmedText.Length == 0)40 return null;41 return new Comment(trimmedText, ConvertToCompatibleFilePosition(c.Location, c.Text.Length - trimmedText.Length));42 }43 private static Scenario[] ConvertToCompatibleScenarios(IEnumerable<Gherkin.Ast.ScenarioDefinition> scenarioDefinitions)44 {45 return scenarioDefinitions.Select(ConvertToCompatibleScenario).ToArray();46 }47 private static Scenario ConvertToCompatibleScenario(Gherkin.Ast.ScenarioDefinition sd)48 {49 var convertToCompatibleTags = ConvertToCompatibleTags(sd.GetTags());50 var result = sd is global::Gherkin.Ast.ScenarioOutline51 ? new ScenarioOutline(sd.Keyword, sd.Name, sd.Description, convertToCompatibleTags, ConvertToCompatibleSteps(sd.Steps), ConvertToCompatibleExamples(((global::Gherkin.Ast.ScenarioOutline)sd).Examples))52 : new Scenario(sd.Keyword, sd.Name, sd.Description, convertToCompatibleTags, ConvertToCompatibleSteps(sd.Steps));53 result.FilePosition = ConvertToCompatibleFilePosition(sd.Location);54 return result;55 }56 private static Examples ConvertToCompatibleExamples(IEnumerable<global::Gherkin.Ast.Examples> examples)57 {58 return new Examples(examples.Select(e => new ExampleSet(e.Keyword, e.Name, e.Description, ConvertToCompatibleTags(e.Tags), ConvertToCompatibleExamplesTable(e))).ToArray());59 }60 private static GherkinTable ConvertToCompatibleExamplesTable(global::Gherkin.Ast.Examples examples)61 {62 return new GherkinTable(ConvertToCompatibleRow(examples.TableHeader), examples.TableBody.Select(ConvertToCompatibleRow).ToArray());63 }64 private static GherkinTableRow ConvertToCompatibleRow(global::Gherkin.Ast.TableRow tableRow)65 {66 return new GherkinTableRow(tableRow.Cells.Select(c => new GherkinTableCell(c.Value)).ToArray())67 {68 FilePosition = ConvertToCompatibleFilePosition(tableRow.Location)69 };70 }71 private static ScenarioSteps ConvertToCompatibleSteps(IEnumerable<global::Gherkin.Ast.Step> steps)72 {73 return new ScenarioSteps(steps.Select(s => ConvertToCompatibleStep((SpecFlowStep)s)).ToArray());74 }75 private static ScenarioStep ConvertToCompatibleStep(SpecFlowStep step)76 {77 ScenarioStep result = null;78 if (step.StepKeyword == StepKeyword.Given)79 result = new Given {StepKeyword = step.StepKeyword };80 else if (step.StepKeyword == StepKeyword.When)81 result = new When {StepKeyword = step.StepKeyword };82 else if (step.StepKeyword == StepKeyword.Then)83 result = new Then {StepKeyword = step.StepKeyword };84 else if (step.StepKeyword == StepKeyword.And)85 result = new And { StepKeyword = step.StepKeyword };86 else if (step.StepKeyword == StepKeyword.But)87 result = new But {StepKeyword = step.StepKeyword };88 if (result == null)89 throw new NotSupportedException();90 result.Keyword = step.Keyword;91 result.Text = step.Text;92 result.ScenarioBlock = step.ScenarioBlock;93 result.MultiLineTextArgument = step.Argument is global::Gherkin.Ast.DocString ? ((global::Gherkin.Ast.DocString) step.Argument).Content : null;94 result.TableArg = step.Argument is global::Gherkin.Ast.DataTable ? ConvertToCompatibleTable(((global::Gherkin.Ast.DataTable) step.Argument).Rows) : null;95 result.FilePosition = ConvertToCompatibleFilePosition(step.Location);96 return result;97 }98 private static FilePosition ConvertToCompatibleFilePosition(global::Gherkin.Ast.Location location, int columnDiff = 0)99 {100 if (location == null)101 return null;102 return new FilePosition(location.Line, location.Column + columnDiff);103 }104 private static GherkinTable ConvertToCompatibleTable(IEnumerable<global::Gherkin.Ast.TableRow> rows)105 {106 var rowsArray = rows.ToArray();107 return new GherkinTable(ConvertToCompatibleRow(rowsArray.First()), rowsArray.Skip(1).Select(ConvertToCompatibleRow).ToArray());108 }109 private static Background ConvertToCompatibleBackground(global::Gherkin.Ast.Background background)110 {111 if (background == null)112 return null;113 return new Background(background.Keyword, background.Name, background.Description, ConvertToCompatibleSteps(background.Steps))114 {115 FilePosition = ConvertToCompatibleFilePosition(background.Location)116 };117 }118 private static Tags ConvertToCompatibleTags(IEnumerable<global::Gherkin.Ast.Tag> tags)119 {120 if (tags == null || !tags.Any())121 return null;122 return new Tags(tags.Select(t => new Tag(t.GetNameWithoutAt())).ToArray());123 }124 }125}...

Full Screen

Full Screen

FeatureFileTests.cs

Source:FeatureFileTests.cs Github

copy

Full Screen

...59 //assert.60 Assert.Null(scenario);61 }62 [Fact]63 public void GetBackground_Retrieves_If_Present()64 {65 var sut = new FeatureFile(CreateGherkinDocumentWithBackground());66 var background = sut.GetBackground();67 Assert.NotNull(background);68 }69 [Fact]70 public void GetBackground_Gives_Null_If_Not_Present()71 {72 var sut = new FeatureFile(CreateGherkinDocumentWithScenario("test"));73 var background = sut.GetBackground();74 Assert.Null(background);75 }76 private static Gherkin.Ast.GherkinDocument CreateGherkinDocumentWithScenario(77 string scenario,78 Gherkin.Ast.StepArgument stepArgument = null)79 {80 return new Gherkin.Ast.GherkinDocument(81 new Gherkin.Ast.Feature(new Gherkin.Ast.Tag[0], null, null, null, null, null, new Gherkin.Ast.ScenarioDefinition[]82 {83 new Gherkin.Ast.Scenario(84 new Gherkin.Ast.Tag[0],85 null,86 null,87 scenario,88 null,89 new Gherkin.Ast.Step[]{ })90 }),91 new Gherkin.Ast.Comment[0]);92 }93 private static Gherkin.Ast.GherkinDocument CreateGherkinDocumentWithBackground()94 {95 return new Gherkin.Ast.GherkinDocument(96 new Gherkin.Ast.Feature(new Gherkin.Ast.Tag[0], null, null, null, null, null, new Gherkin.Ast.ScenarioDefinition[]97 {98 new Gherkin.Ast.Background(99 null,100 null,101 null,102 null,103 new Gherkin.Ast.Step[]{ })104 }),105 new Gherkin.Ast.Comment[0]);106 }107 private static Gherkin.Ast.GherkinDocument CreateGherkinDocumentWithScenarioOutline(108 string scenario,109 Gherkin.Ast.StepArgument stepArgument = null)110 {111 return new Gherkin.Ast.GherkinDocument(112 new Gherkin.Ast.Feature(new Gherkin.Ast.Tag[0], null, null, null, null, null, new Gherkin.Ast.ScenarioDefinition[]...

Full Screen

Full Screen

GherkinScenarioDefinitionTests.cs

Source:GherkinScenarioDefinitionTests.cs Github

copy

Full Screen

...7{8 public class GherkinScenarioTests9 {10 [Fact]11 public void ApplyBackground_WithNoBackground_ThrowsArgumentNullException()12 {13 var scenario = CreateTestScenario();14 Assert.Throws<ArgumentNullException>(() => scenario.ApplyBackground(null));15 }16 [Fact]17 public void ApplyBackground_WithBackground_PrependsBackgroundSteps()18 { 19 var scenario = CreateTestScenario();20 var backgroundSteps = new Gherkin.Ast.Step[] { new Gherkin.Ast.Step(null, null, "background", null) };21 var background = new Gherkin.Ast.Background(null, null, null, null, backgroundSteps);22 var modified = scenario.ApplyBackground(background);23 24 Assert.Equal(scenario.Location, modified.Location);25 Assert.Equal(scenario.Keyword, modified.Keyword);26 Assert.Equal(scenario.Name, modified.Name);27 Assert.Equal(scenario.Description, modified.Description);28 29 Assert.Equal(2, modified.Steps.Count());30 Assert.Equal("background", modified.Steps.ElementAt(0).Text);31 Assert.Equal("step", modified.Steps.ElementAt(1).Text);32 } 33 private static Gherkin.Ast.Scenario CreateTestScenario()34 {35 var tags = new Gherkin.Ast.Tag[] { new Gherkin.Ast.Tag(null, "test") };36 var location = new Gherkin.Ast.Location(1, 1);...

Full Screen

Full Screen

FeatureFile.cs

Source:FeatureFile.cs Github

copy

Full Screen

...12 public global::Gherkin.Ast.Scenario GetScenario(string scenarioName)13 {14 return GherkinDocument.Feature.Children.FirstOrDefault(s => s.Name == scenarioName) as global::Gherkin.Ast.Scenario;15 }16 public global::Gherkin.Ast.Background GetBackground()17 {18 return GherkinDocument.Feature.Children.OfType<global::Gherkin.Ast.Background>().SingleOrDefault();19 }20 internal ScenarioOutline GetScenarioOutline(string scenarioOutlineName)21 {22 return GherkinDocument.Feature.Children.FirstOrDefault(s => s.Name == scenarioOutlineName) as global::Gherkin.Ast.ScenarioOutline;23 }24 }25}...

Full Screen

Full Screen

GherkinScenarioExtensions.cs

Source:GherkinScenarioExtensions.cs Github

copy

Full Screen

...3namespace Xunit.Gherkin.Quick4{5 internal static class GherkinScenarioExtensions6 {7 public static global::Gherkin.Ast.Scenario ApplyBackground(8 this global::Gherkin.Ast.Scenario @this, 9 global::Gherkin.Ast.Background background) 10 {11 if(background == null)12 throw new ArgumentNullException(nameof(background));13 var stepsWithBackground = background.Steps.Concat(@this.Steps).ToArray();14 return new global::Gherkin.Ast.Scenario(15 @this.Tags.ToArray(), 16 @this.Location, 17 @this.Keyword, 18 @this.Name, 19 @this.Description, 20 stepsWithBackground);21 } 22 }23}...

Full Screen

Full Screen

Background

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Gherkin.Ast;7{8 {9 static void Main(string[] args)10 {11 Background background = new Background(new List<Tag>(), "Background", new List<Step>(), 1);12 Console.WriteLine(background.BackgroundKeyword);13 Console.WriteLine(background.Description);14 Console.WriteLine(background.Location.Line);15 Console.WriteLine(background.Name);16 Console.WriteLine(background.Steps.Count);17 Console.WriteLine(background.Tags.Count);18 Console.ReadLine();19 }20 }21}

Full Screen

Full Screen

Background

Using AI Code Generation

copy

Full Screen

1using Gherkin.Ast;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7{8 {9 static void Main(string[] args)10 {11 Background background = new Background("Background", "Background description", new List<Step> { new Step("Given", "Given step", 1, null, null), new Step("When", "When step", 2, null, null) });12 Console.WriteLine("Background: " + background.Name);13 Console.WriteLine("Description: " + background.Description);14 Console.WriteLine("Steps: ");15 foreach (var step in background.Steps)16 {17 Console.WriteLine("\t" + step.Keyword + " " + step.Text);18 }19 Console.ReadKey();20 }21 }22}

Full Screen

Full Screen

Background

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using TechTalk.SpecFlow;7{8 {9 [Given(@"I have entered (.*) into the calculator")]10 public void GivenIHaveEnteredIntoTheCalculator(int p0)11 {12 ScenarioContext.Current.Pending();13 }14 [When(@"I press add")]15 public void WhenIPressAdd()16 {17 ScenarioContext.Current.Pending();18 }19 [Then(@"the result should be (.*) on the screen")]20 public void ThenTheResultShouldBeOnTheScreen(int p0)21 {22 ScenarioContext.Current.Pending();23 }24 }25}26using System;27using System.Collections.Generic;28using System.Linq;29using System.Text;30using System.Threading.Tasks;31using TechTalk.SpecFlow;32{33 {34 [Given(@"I have entered (.*) into the calculator")]35 public void GivenIHaveEnteredIntoTheCalculator(int p0)36 {37 ScenarioContext.Current.Pending();38 }39 [When(@"I press add")]40 public void WhenIPressAdd()41 {42 ScenarioContext.Current.Pending();43 }44 [Then(@"the result should be (.*) on the screen")]45 public void ThenTheResultShouldBeOnTheScreen(int p0)46 {47 ScenarioContext.Current.Pending();48 }49 }50}51using System;52using System.Collections.Generic;53using System.Linq;54using System.Text;55using System.Threading.Tasks;56using TechTalk.SpecFlow;57{58 {59 [Given(@"I have entered (.*) into the calculator")]60 public void GivenIHaveEnteredIntoTheCalculator(int p0)61 {

Full Screen

Full Screen

Background

Using AI Code Generation

copy

Full Screen

1var background = new Gherkin.Ast.Background(new List<Gherkin.Ast.Tag>(), "Background", "Background description", new List<Gherkin.Ast.Step>());2background.Background();3var background = new Gherkin.Ast.Background(new List<Gherkin.Ast.Tag>(), "Background", "Background description", new List<Gherkin.Ast.Step>());4background.Background();5var background = new Gherkin.Ast.Background(new List<Gherkin.Ast.Tag>(), "Background", "Background description", new List<Gherkin.Ast.Step>());6background.Background();7var background = new Gherkin.Ast.Background(new List<Gherkin.Ast.Tag>(), "Background", "Background description", new List<Gherkin.Ast.Step>());8background.Background();9var background = new Gherkin.Ast.Background(new List<Gherkin.Ast.Tag>(), "Background", "Background description", new List<Gherkin.Ast.Step>());10background.Background();11var background = new Gherkin.Ast.Background(new List<Gherkin.Ast.Tag>(), "Background", "Background description", new List<Gherkin.Ast.Step>());12background.Background();13var background = new Gherkin.Ast.Background(new List<Gherkin.Ast.Tag>(), "Background", "Background description", new List<Gherkin.Ast.Step>());14background.Background();15var background = new Gherkin.Ast.Background(new List<Gherkin.Ast.Tag>(), "Background", "Background description", new List<Gherkin.Ast.Step>());16background.Background();17var background = new Gherkin.Ast.Background(new List<Gherkin.Ast.Tag

Full Screen

Full Screen

Background

Using AI Code Generation

copy

Full Screen

1var background = new Background("Background", "Background", new List<Step>(), new List<Tag>());2background.Background("Background", "Background", new List<Step>(), new List<Tag>());3background.Background("Background", "Background", new List<Step>(), new List<Tag>(), new List<Comment>());4var background = new Background("Background", "Background", new List<Step>(), new List<Tag>(), new List<Comment>());5background.Background("Background", "Background", new List<Step>(), new List<Tag>(), new List<Comment>());6background.Background("Background", "Background", new List<Step>(), new List<Tag>(), new List<Comment>());7var background = new Background("Background", "Background", new List<Step>(), new List<Tag>(), new List<Comment>());8background.Background("Background", "Background", new List<Step>(), new List<Tag>(), new List<Comment>());9background.Background("Background", "Background", new List<Step>(), new List<Tag>(), new List<Comment>());10var background = new Background("Background", "Background", new List<Step>(), new List<Tag>(), new List<Comment>());11background.Background("Background", "Background", new List<Step>(), new List<Tag>(), new List<Comment>());12background.Background("Background", "Background", new List<Step>(), new List<Tag>(), new List<Comment>());13var background = new Background("Background", "Background", new List<Step>(), new List<Tag>(), new List<Comment>());14background.Background("Background", "Background", new List<Step>(), new List<Tag>(), new List<Comment>());15background.Background("Background", "Background", new List<Step>(), new List<Tag>(), new List<Comment>());16var background = new Background("Background", "Background", new List<Step>(), new List<Tag>(), new List<Comment>());17background.Background("Background", "Background", new List<Step>(), new List<Tag>(), new List<Comment>());18background.Background("Background", "Background", new List<Step>(), new List<Tag>(), new List<Comment>());

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gherkin-dotnet automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in Background

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful