Donate : Link
Medium Blog : Link
Applications : Link

Cucumber Tutorial Index Page: Link
Annotation is a predefined text, which holds a specific meaning. It lets the compiler/interpreter know, what should be done upon execution. Cucumber has got the following few annotations −
Given −
- It specifies pre-condition. It is basically a known state.
- Example – User navigate to xyz.com
When −
- This is used when some actions to be performed.
- Example – User enter valid id “user1” and psw “user1”
Then −
- The expected outcome or result should be placed here.
- Example – Login should be successful
And −
- And is used to continue to combine two or more steps same type of actions.
- Sample feature file:
Feature: Login functionality feature
Scenario: Login functionality with valid data
Given User navigate to xyz.com
When User enter valid id "user1"
And User enter psw as "user1"
Then Login should be successful
And Home page should be displayed
But −
- It signifies logical OR condition between any two statements. OR can be used in conjunction with GIVEN, WHEN and THEN statement.
- Example − THEN login should be successful. BUT home page should not be missing.
Scenario −
- Basically a scenario presents a particular functionality which is under test.
- By seeing the scenario user should be able to understand the intent behind the scenario and what the test is all about.
- Each scenario should follow Given, When, Then format. This language is called as “Gherkin”.
Scenario Outline −
- TO BE COVERED LATER
Examples −
- TO BE COVERED LATER
Background −
- Whenever any step is required to perform in each scenario then those steps need to be placed in background.
- Sample feature file:
Feature: Login functionality feature
Background:
Given User navigate to xyz.com
Scenario: Login functionality with valid data
When User enter valid id "user1" and psw "user1"
Then Login should be successful
Scenario: Login functionality with invalid data
When User enter valid id "code" and psw "factory"
Then Error message should be thrown
