1

Does anyone know how to use Gherkin to parse custom feature file? I want to create a tool to process feature file and execute custom java code. I want Gherkin to process file similar to this:

SCENARIO: My Fist sample test
   WHEN [this condition met]
   USE [this dataset]
   THEN [test this java code]
user3431327
  • 135
  • 4
  • 14
  • are you looking for a way to have customized GIVEN/WHEN/THEN keywords? If so you can try QAF which supports [Keywords Synonyms](https://qmetry.github.io/qaf/latest/BDD_Keywords_Synonyms.html). For example: `Given=USE;Provided;Having` – user861594 Dec 04 '18 at 01:44
  • No, I'm looking for a instruction or code sample to use Gherkin and parse the input instruction. – user3431327 Dec 04 '18 at 14:54

2 Answers2

3

You also can refer one of the gherkin parser GherkinFileParser.java used in qaf. From the unit test below is the usage:

GherkinFileParser parser = new GherkinFileParser();
List<Scenario> scenarios = new ArrayList<Scenario>();
parser.parse("resources/features/gherkin.feature", scenarios);

for (Scenario scenario : scenarios) {
 //...
}
user861594
  • 5,733
  • 3
  • 29
  • 45
-1

Gherkin is designed for storing descriptions of business behaviour. Its not a tool for writing scripts or doing programming. If you feel you want to program in gherkin you should consider either

1) Moving the programming up outside of Cucumber, so you run multiple instances of Cucumber 2) Moving the programming DOWN into the step definitions and helper methods.

You would have to do some hardcore programming and basically write a new language (it wouldn't be Gherkin anymore) to do what you've described.

diabolist
  • 3,990
  • 1
  • 11
  • 15
  • I dont think i explained well enough. i'm not trying to use Gherkin to write scripts. I'm simply trying to use Gherkin as input tool for my project, similar to how cucumber uses Gherkin to take input. – user3431327 Dec 11 '18 at 15:37
  • then you probably should rephrase the question and look at the tools Cucumber uses to parse Gherkin. You can probably find out more at the main cucumber sites. Its all open source – diabolist Dec 14 '18 at 11:25