Gherkin
Pages 76
- Home
- A Table Of Content
- A Whole New World
- Autotest Integration
- Background
- Browsers and Transactions
- Calling Steps from Step Definitions
- Configuring the Scenario Execution Context (World)
- Conjunction Steps (Antipattern)
- Console Colours
- Continuous Integration
- Contributing
- Cucumber Backgrounder
- Cucumber Feature
- Cucumber for Perl
- Cucumber JVM
- cucumber.yml
- Custom Formatters
- Debugging
- Environment Variables
- Examples
- Feature Coupled Step Definitions (Antipattern)
- Feature Introduction
- Fixtures
- FunFX and Flex
- Get in touch
- Gherkin
- Given When Then
- Given When Then (new)
- Hooks
- Install
- Introduction to Cucumber for non programmers
- IronRuby and .NET
- IronRuby and Mono
- JavaScript and AJAX
- Jenkins integration
- JRuby and Java
- Merb
- Mocking and Stubbing with Cucumber
- Multiline Step Arguments
- Patterns
- PHP
- Profiles
- Projects Using Cucumber
- Python
- RDoc
- Related tools
- RSpec Expectations
- Ruby on Rails
- Running Features
- SAP Enterprise Portal Behavior Testing
- Scenario Outlines
- Setting up Selenium
- Setting up Steam
- Simple Expressions
- Sinatra
- Snailgun and Cucumber
- Spoken languages
- Step Argument Transforms
- Step Definitions
- Step Organization
- subdomain_fu and incorrect redirection to " body You are being redirected body " page
- Tables
- Tags
- Translations
- Troubleshooting
- Tutorials and Related Blog Posts
- Upgrading
- Using AE
- Using MiniTest
- Using Rake
- Using RCov with Cucumber and Rails
- Using Test::Unit
- Watircraft
- watircuke
- Wire Protocol
- Show 61 more pages…
Clone this wiki locally
Gherkin is the language that Cucumber understands. It is a Business Readable, Domain Specific Language that lets you describe 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 (60 at the time of writing), so that your team can use the keywords in your own language.
There are a few conventions.
- Single Gherkin source file contains a description of a single feature.
- Source files have
.featureextension.
Gherkin Syntax
Like Python and YAML, Gherkin is a line-oriented language that uses indentation to define structure. Line endings terminate statements (eg, steps). Either spaces or tabs may be used for indentation (but spaces are more portable). Most lines start with a keyword.
Comment lines are allowed anywhere in the file. They begin with zero or more spaces, followed by a hash sign (#) and some amount of text.
The parser divides the input into features, scenarios and steps. When you run the feature the trailing portion (after the keyword) of each step is matched to a Ruby code block called Step Definitions.
A Gherkin source file usually looks like this
1: Feature: Some terse yet descriptive text of what is desired 2: Textual description of the business value of this feature 3: Business rules that govern the scope of the feature 4: Any additional information that will make the feature easier to understand 5: 6: Scenario: Some determinable business situation 7: Given some precondition 8: And some other precondition 9: When some action by the actor 10: And some other action 11: And yet another action 12: Then some testable outcome is achieved 13: And something else we can check happens too 14: 15: Scenario: A different situation 16: ...
First line starts the feature. Lines 2–4 are unparsed text, which is expected to describe the business value of this feature. Line 6 starts a scenario. Lines 7–13 are the steps for the scenario. Line 15 starts next scenario and so on.
Read more
- Feature Introduction – general structure of a feature
- Given-When-Then – steps