Questions tagged [gherkin]

Gherkin is the language used to write specifications for Cucumber, Specflow and similar BDD frameworks. It is a business-readable, domain-specific language that lets you describe your software’s behaviour without detailing how that behaviour is implemented.

Gherkin is the language used to write specifications for Cucumber, Specflow and similar BDD frameworks. It is a business-readable, domain-specific language that lets you describe your software’s behaviour without detailing how that behaviour is implemented.

Gherkin serves two purposes — documentation and automated tests. The third is a bonus feature — when it yells in red it’s talking to you, telling you what code you should write.

Gherkin’s grammar is defined in the Treetop grammar that is part of the Cucumber codebase. The grammar exists in different flavours for many spoken languages (37 at the time of writing), so that your team can use the keywords in your own language.

There are a few conventions:

  • A single Gherkin source file contains a description of a single feature.
  • Source files have the extension .feature.
  • There is a fundamental pattern to each Gherkin scenario, with a context: (Given), an event (When), and an outcome (Then).

Gherkin was invented by Alsak Hellesoy.

You can read more about Gherkin here: https://github.com/cucumber/gherkin/wiki

Documentation of Cucumber and Gherkin: https://www.cucumber.io/

.NET implementation: http://www.specflow.org/

Python implementation: https://behave.readthedocs.io/

1169 questions
8
votes
5 answers

Does if else concept available in feature file (Gherkin language)?

Is there anyway where we can use if/else concept in feature file? For example: Scenario: User should be able to check login page Given I am on login page When I click on SignIn button Then I should be in home page If yes Then I will…
user1553680
  • 339
  • 3
  • 6
  • 18
8
votes
2 answers

How to get Gherkin syntax highlighting for .feature files in Visual Studio?

There's no highlighting for Feature, Scenario, Given, When, Then, etc. keywords by default. Is there a ready made template out there to enable this?
thenextwebguy
  • 285
  • 5
  • 11
8
votes
3 answers

Is there a "for each" or equivalent syntax for Gherkin/Cucumber?

Is there any equivalent "for each" statement for Gherkin? In the following scenario, the page I am testing has multiple date fields that I'd like to run the same test examples on. Here is the scenario that I would like to model. Scenario Outline:…
CLothian
  • 105
  • 1
  • 4
8
votes
2 answers

Gherkin - simply re-use Given statements as When statements... acceptable?

Here are three example BDD statements that should help explain my question: Scenario: User logs in Given I am on the login screen When I enter the valid username "myUsername" And I enter the valid password "myPassword" And I press the login…
Charlie S
  • 4,366
  • 6
  • 59
  • 97
7
votes
1 answer

cucumber-js: specify path for step-definitions file

I have multiple projects and I would like to implement cucumber-js E2E testing for all of them. I have a step definitions file which can be used for testing all of these projects, however I want to have multiple feature files with each project…
r.w.20
  • 71
  • 1
  • 2
7
votes
3 answers

Date object in Cucumber

I have a cucumber stepdef like this Given the date of When blah blah Then x y and z Examples: |2015-01-01| |2045-01-01| When I generate stepdefs off of this, I get @Given("^the date of (\\d+)-(\\d+)-(\\d+)$") And the method is generated with…
Steve
  • 4,457
  • 12
  • 48
  • 89
7
votes
2 answers

Pass Array value in cucumber .feature file

I want to pass array value as a parameter from cucumber .feature file, so I can access it from step definition file: I am using this format: Examples: |r1|t1| |abc|[aa,bb,cc]| But I'm getting an error undefined methodeach' for "[aa,bb,cc]":String…
Shobhit Gupta
  • 103
  • 1
  • 1
  • 11
7
votes
2 answers

What makes a Feature and What a scenario in Gherkin and cucumber?

Say I am developing a Shopping cart, BDD, with Cucumber. A cart is rather complex and has many bells-and whistles, but this could be just as well for "a blog" or "a user profile". I've always considered the "cart" to be the Feature and the…
berkes
  • 26,996
  • 27
  • 115
  • 206
7
votes
1 answer

Troubleshooting installing Gherkin 2.1.5

I am trying to install Gherkin 2.1.5, well, actually it is a dependency of https://github.com/opencongress/opencongress. I am using bundle install in the root directory of the code to install, about 20-30 packages got installed and now I'm stuck on…
jett
  • 1,276
  • 2
  • 14
  • 34
7
votes
2 answers

How to increase reusability between SpecFlow/Gherkin steps?

I think I thoroughly understand the concepts and ideas behind SpecFlow, but even after reading the Secret Ninja Cucumber Scrolls, The Cucumber Book, and going through the various forums I'm still unsure about the path to reusability. Our scenarios…
Dennis Doomen
  • 8,368
  • 1
  • 32
  • 44
6
votes
4 answers

Gherkin "OR" syntax to reduce repetition with BDD

Does anyone know of a way to achieve this or do they think it's a good idea. To have an OR style syntax in Gherkin for reducing repetition but maintaining human readability (hopefully). I'm thinking of cases where clause combinations are expanded…
Eamonn Boyle
  • 466
  • 1
  • 4
  • 7
6
votes
1 answer

Cucumber launched from Spring Boot app not finding the glue classes in the jar

We have a Spring Boot app and we want to start from within this app the execution of a Cucumber feature. Whenever the user clicks a button in the spring app, then the call comes in a class (CucumberTestService) where we start the execution of our…
Lavinia
  • 141
  • 7
6
votes
3 answers

Cucumber with IntelliJ not finding step definitions

I encountered the following issue. I have four Cucumber feature files in IntelliJ. I added the Cucumber support via the IntelliJ plugin. After creating my features I edited my configuration like followed so i can execute the feature files. Glue…
Jan Kreischer
  • 679
  • 3
  • 8
  • 21
6
votes
1 answer

Where can I find out how best to use Gherkin tags?

I've been using SpecFlow for my acceptance tests. This uses Gherkin (the DSL Cucumber uses). It includes an interesting feature called "tags". I can see the practicalities of its use, but am not sure about what might constitute good practice for…
MrBlueSky
  • 728
  • 6
  • 20
6
votes
3 answers

How to use cucumber/gherkin in different language?

I'm setting up a test environment with Cucumber, Sikuli and Eclipse in my company. I've managed to get everything working just fine, but now I need to make the .feature files work in portuguese. As far as I know, all I had to do was put the comment…