Sunday, 29 April 2018

Gherkin: Given, When and Then keywords

Given keyword is used to setup the context.
When keyword is used to setup the interactions with the application.
Then keyword is used to tell, what will be the expectation, on the interactions specified in When clause.

Example1
Feature: Login 

 Login should be quick and friendly.
 
Scenario: Successful Login 
 Users should be logged in successfully by providing correct username and password.
  
 Given I have chosen to Login 
 When I log in with user name "krishna" and password "password123" 
 Then I should be logged in successfully 
 And I should see a personalized greeting message

Example 2
Feature: Credit card validation 

Scenario: Validate number of digits in credit card 

 Given I am the customer of website 
 When I entered a credit card number that is not exactly 16 digits 
 Then I should be notified with error message 
 And ask to reenter credit card number

Example 3
Feature: Student Pass status 

 Student pass status is decided based on below criteria.
 ---------------------------------------------------
  < 60  : second class
  >= 60 && < 70 : First class
  > 70 : Distinction
 ---------------------------------------------------
 
Scenario: Checking Second Class 
 Student will be notified as second class, if he got < Sixty percentage
  
 Given I am a student 
 When I got Fifty Five percentage of marks 
 Then I should be notified as Second Class 
 
Scenario: Checking First Class 
 Student will be notified as First class, if he got >= Sixty && < Seventy percentage
  
 Given I am a student 
 When I got greater than or equal to sixty and < seventy percentage of marks 
 Then I should be notified as First Class 
 
Scenario: Checking Destinction 
 Student will be notified as Distinction if he got > Seventy percentage
  
 Given I am a student 
 When I got greate than seventy percentage of marks 
 Then I should be notified as Distinction






Previous                                                 Next                                                 Home

No comments:

Post a Comment