CUCUMBER (1) (1)
CUCUMBER (1) (1)
CUCUMBER
Behavior Driven Development
Cucumber:
Cucumber is a testing framework which supports Behavior Driven Development (BDD). It
lets us define application behavior in plain meaningful English text using a simple grammar
defined by a language called Gherkin
Gherkin keywords:
Feature: Keyword
Each Gherkin file begins with a Feature keyword. Feature defines the logical test
functionality you will test in this feature file. For e.g, if you are testing a payment
gateway your Feature will become Payment Gateway or if you are testing the LogIn
functionality then the Feature will become Login. The idea of having a feature file is
to put down a summary of what you will be testing. This will serve as the
documentation for your tests as well as a good point to start for a new team member.
Note that a feature keyword is present at the starting of the feature file.
Or
Scenario: Keyword
Each Feature will contain a number of tests to test the feature. Each test is called
a Scenario and is described using the Scenario: keyword.
Scenario: Search a product and add the first result/product to the User basket
Or
Given: Keyword
Given defines a precondition to the test. For e.g. In the shopping website, assume
that the LogIn page link is only present on the Home Page, so the precondition for
clicking the LogIn link is that the user is at the Home Page. If user is not at the Home
Page, user would not be able to enter Username & Password. This precondition can
be expressed in Gherkin like this:
When: Keyword
When keyword defines the test action that will be executed. By test action we mean
the user input action.
Here user is performing some action using When keyword, clicking on the LogIn link.
We can see that when defines the action taken by the user. It's the event that will
cause the actual change in state of the application.
Then: Keyword
Then keyword defines the Outcome of previous steps. We can understand it best by
looking at the test above and adding a Then step there.
Scenario: Successful Login with Valid Credentials Given User is on Home Page
Here we can see that Then is the outcome of the steps above. The reader of this
test would easily be able to relate to Then step and would understand that when the
above conditions are fulfilled then the Then step will be executed.
And: Keyword
And keyword is used to add conditions to your steps. Let's look at it by modifying our
example a little
Or