How to use pickleTags method in Cucumber-gherkin

Best JavaScript code snippet using cucumber-gherkin

Run Cucumber-gherkin automation tests on LambdaTest cloud grid

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

compiler.js

Source: compiler.js Github

copy
1var countSymbols = require('../count_symbols');
2
3function Compiler() {
4  this.compile = function (gherkin_document) {
5    var pickles = [];
6
7    if (gherkin_document.feature == null) return pickles;
8
9    var feature = gherkin_document.feature;
10    var language = feature.language;
11    var featureTags = feature.tags;
12    var backgroundSteps = [];
13
14    feature.children.forEach(function (scenarioDefinition) {
15      if(scenarioDefinition.type === 'Background') {
16        backgroundSteps = pickleSteps(scenarioDefinition);
17      } else if(scenarioDefinition.type === 'Scenario') {
18        compileScenario(featureTags, backgroundSteps, scenarioDefinition, language, pickles);
19      } else {
20        compileScenarioOutline(featureTags, backgroundSteps, scenarioDefinition, language, pickles);
21      }
22    });
23    return pickles;
24  };
25
26  function compileScenario(featureTags, backgroundSteps, scenario, language, pickles) {
27    if (scenario.steps.length == 0) return;
28
29    var steps = [].concat(backgroundSteps);
30
31    var tags = [].concat(featureTags).concat(scenario.tags);
32
33    scenario.steps.forEach(function (step) {
34      steps.push(pickleStep(step));
35    });
36
37    var pickle = {
38      tags: pickleTags(tags),
39      name: scenario.name,
40      language: language,
41      locations: [pickleLocation(scenario.location)],
42      steps: steps
43    };
44    pickles.push(pickle);
45  }
46
47  function compileScenarioOutline(featureTags, backgroundSteps, scenarioOutline, language, pickles) {
48    if (scenarioOutline.steps.length == 0) return;
49
50    scenarioOutline.examples.filter(function(e) { return e.tableHeader != undefined; }).forEach(function (examples) {
51      var variableCells = examples.tableHeader.cells;
52      examples.tableBody.forEach(function (values) {
53        var valueCells = values.cells;
54        var steps = [].concat(backgroundSteps);
55        var tags = [].concat(featureTags).concat(scenarioOutline.tags).concat(examples.tags);
56
57        scenarioOutline.steps.forEach(function (scenarioOutlineStep) {
58          var stepText = interpolate(scenarioOutlineStep.text, variableCells, valueCells);
59          var args = createPickleArguments(scenarioOutlineStep.argument, variableCells, valueCells);
60          var pickleStep = {
61            text: stepText,
62            arguments: args,
63            locations: [
64              pickleLocation(values.location),
65              pickleStepLocation(scenarioOutlineStep)
66            ]
67          };
68          steps.push(pickleStep);
69        });
70
71        var pickle = {
72          name: interpolate(scenarioOutline.name, variableCells, valueCells),
73          language: language,
74          steps: steps,
75          tags: pickleTags(tags),
76          locations: [
77            pickleLocation(values.location),
78            pickleLocation(scenarioOutline.location)
79          ]
80        };
81        pickles.push(pickle);
82
83      });
84    });
85  }
86
87  function createPickleArguments(argument, variableCells, valueCells) {
88    var result = [];
89    if (!argument) return result;
90    if (argument.type === 'DataTable') {
91      var table = {
92        rows: argument.rows.map(function (row) {
93          return {
94            cells: row.cells.map(function (cell) {
95              return {
96                location: pickleLocation(cell.location),
97                value: interpolate(cell.value, variableCells, valueCells)
98              };
99            })
100          };
101        })
102      };
103      result.push(table);
104    } else if (argument.type === 'DocString') {
105      var docString = {
106        location: pickleLocation(argument.location),
107        content: interpolate(argument.content, variableCells, valueCells)
108      };
109      result.push(docString);
110    } else {
111      throw Error('Internal error');
112    }
113    return result;
114  }
115
116  function interpolate(name, variableCells, valueCells) {
117    variableCells.forEach(function (variableCell, n) {
118      var valueCell = valueCells[n];
119      var search = new RegExp('<' + variableCell.value + '>', 'g');
120      name = name.replace(search, valueCell.value);
121    });
122    return name;
123  }
124
125  function pickleSteps(scenarioDefinition) {
126    return scenarioDefinition.steps.map(function (step) {
127      return pickleStep(step);
128    });
129  }
130
131  function pickleStep(step) {
132    return {
133      text: step.text,
134      arguments: createPickleArguments(step.argument, [], []),
135      locations: [pickleStepLocation(step)]
136    }
137  }
138
139  function pickleStepLocation(step) {
140    return {
141      line: step.location.line,
142      column: step.location.column + (step.keyword ? countSymbols(step.keyword) : 0)
143    };
144  }
145
146  function pickleLocation(location) {
147    return {
148      line: location.line,
149      column: location.column
150    }
151  }
152
153  function pickleTags(tags) {
154    return tags.map(function (tag) {
155      return pickleTag(tag);
156    });
157  }
158
159  function pickleTag(tag) {
160    return {
161      name: tag.name,
162      location: pickleLocation(tag.location)
163    };
164  }
165}
166
167module.exports = Compiler;
168
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Cucumber-gherkin on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)