Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Gherkin is a plain English text language, which helps the tool - Behat/Cucumber to
interpret and execute the test scripts.
Gherkin provides the common set of keywords in English text, which can be used by
people amongst the different community and yet get the same output in the form of test
scripts.
This is a complete feature file. It starts with a required Feature section and a
description. The description is optional, and it may have as many or as few lines as
desired. The description will not affect automation at all – think of it as a comment. As
an Agile best practice, it should include the user story for the features under test. This
feature file then has one Scenario section with a title and one each of Given–When–
Then steps in order. It could have more scenarios, but for simplicity, this example has
only one. The indents and blank lines also make the feature file easy to read
Tags Tags are a great way to classify scenarios. They can be used to selectively run
tests based on tag name, and they can be used to apply before-and-after wrappers
around scenarios. Most BDD frameworks support tags. Any scenario can be given tags
like this:
Tags start with the “@” symbol. Tag names are case-sensitive and whitespace-
separated. As a best practice, they should be lowercase and use hyphens (“-“) between
separate words. Tags must be put on the line before a Scenario or Scenario Outline
section begins. Any number of tags may be used
Steps Definitions
We have got our feature file ready with the test scenarios defined. However, this is not
the complete job done. Behat doesn’t really know which piece of code is to be
executed for any specific scenario outlined in a feature file.
This calls the need of an intermediate – Step Definition file. Steps definition file stores
the mapping between each step of the scenario defined in the feature file with a code
of function to be executed.
So, now when Behat executes a step of the scenario mentioned in the feature file, it
scans the step definition file and figures out which function is to be called.
Step 1:
Create a folder as you want in any drive. I have created folder “alp_behat” in D:/alp_behat.
Step 2:
Open the command prompt direct to D:/alp_behat > and type the following command to download
the ‘composer.phar’
Step 3:
Create a JSON file “composer.json” defining your dependencies as given below inside it. This will install all
specified dependencies in ‘composer.json’
{
"require": {
"behat/behat": "@stable",
"behat/mink": "@stable",
"behat/mink-extension": "@stable",
"behat/mink-goutte-driver": "*",
"behat/mink-selenium2-driver": "*"
Step 4: },
"config": {
"bin-dir":“php
Run Composer: composer.phar install”
"bin/"
}
}
Step 5:
This will take some time to install all dependencies mentioned in the composer.json and creates the vendor
folder and bin folder.
Step 6:
Add the Behat path "D:\alp_behat\bin" to your system path variable, as follows:
● Right click "Computer" and select "Properties"
● Under "Control Panel Home" select "Advanced system settings"
● In the "Advanced" tab navigate to the bottom and select "Environment Variables"
● In the "System variables" section scroll down and select "Path" and then select the "Edit" button
● Ensure you are at the end of the "Variable value" field and add this to the end of the "Path" value ";
D:\alp_behat\bin;".
Step 7:
Test that Behat has installed correctly by doing the below steps.
Open a new command prompt window and type "Behat --version" (without the quotes). You should see
'Behat version DEV'.
Step 8:
- A features folder,
- A bootstrap folder,
- And the FeatureContext.php file inside the bootstrap folder.
Now your behat installation is complete. Add the feature files to the feature folder (ex: demo.feature).
Step 9:
You need Selenium Server and the corresponding browser drivers (Chromedriver) to test your application on
different browsers.
Server: ‘selenium-server-standalone-2.53.1.jar’
Driver: ‘Chromedriver.exe’
These can be downloaded from ‘http://www.seleniumhq.org/download/’ and ensure these are kept in the
project folder.
Step 10:
In the command prompt go to your project location “D:\alp_behat” and enter below command
“Behat features\demo.feature”
Reference Source:
1. http://docs.behat.org/en/latest/user_guide/initialize.html
2. https://github.com/composer/composer
3. https://github.com/Behat/MinkExtension
4. http://getcomposer.org/download/