Introduction to Gherkin Keywords

Types of Gherkin keywords

 Introduction to Gherkin Keywords

Gherkin not used to create automated exams. Gherkin used to write structured tests. which can later utilize as project documents. The property structured provides us the ability to automate them. This automation performed by Cucumber/SpecFlow Types of Gherkin keywords.

Types of Gherkin keywords

  • Feature
  • Background
  • Scenario
  • Given
  • When
  • Then
  • And
  • But
  • *

Feature: Keyword

Each Gherkin data file begins with an attribute keyword. Feature defines the rational test efficiency you will test in this feature record.

Record: Keyword

Background keyword used to explain steps. which are common to all or any the assessments in the feature record.
Background: Individual Logged In
Scenario: Search a product and add the first end result/product to an individual basket
Given User sought out Lenovo Laptop
When Add the first laptop that shows up in the search result to the basket
Then User container should screen with 1 item

Situation: Keyword

Each Feature will contain some quantity of tests to check the feature. Each test called a Scenario and is also defined using the Scenario: keyword.

Situation: Search a product and add the first consequence/product to the User basket
Circumstance: Successful LogIn with Valid Credentials

A scenario is the same as a test inside our regular development process. Each scenario/test broken down into three parts:

  • Precondition to the test, which stands for with (Given) keyword
  • Test step execution, which signifies with (When) keyword
  • Confirmation of the productivity with expected effect, which stands for with (Then)
Given Keyword

Given defines a precondition to the test. If the user is not at the house Page, the user would not be able to get into Username & Password. This precondition can be indicated in Gherkin like this:

Situation: Successful LogIn with Valid Credentials

  Given Customer is on WEBSITE
  When Individual Navigate to LogIn Page

When Keyword

When keyword defines the test action which will carry out. By test action, we say the user input action.
Situation: Successful LogIn with Valid Credentials
  Given Individual is on WEBSITE
  When End user Navigate to LogIn Site
  The customer is performing some action using When keyword, clicking on the Log in link. We can see that when defines the action used by the user. It is the event that may cause the actual change in talk about of the application.

Then Keyword

Then keyword defines the results of earlier steps. We are able to understand it best by looking at the test above and adding a Then step there.
Feature: LogIn Action Test
Information: This feature will test a login and LogOut functionality
Scenario: Successful Login with Valid Credentials
  Given Customer is on WEBSITE
  When Individual Navigate to LogIn Page
  And User gets into UserName and Password
  Then Message viewed LogIn

Here we can see that Then is the outcome of the steps above. The audience of the test would be able to relate with Then step and would recognize. the mentioned conditions satisfied then step executed.

And Keyword

And keyword used to add conditions to your steps.
that And is being used to add more details to the Given step, it’s adding more conditions. We added three conditions. Use it when you yourself have specified more than one condition. And used to include more conditions to Given, When and statements.

But Keyword

But keyword used to include negative type remarks. It isn’t a hard & fast rule to make use of but only for negative conditions. It seems sensible to use But when will try to add a disorder which is opposite to the idea your test is wanting to set.
Scenario: Unsuccessful Login with InValid Credentials
  Given User is on Home Page
  When Consumer Navigate to LogIn Page
  And User enters Account
  But The user qualifications are wrong
  Then Message displayed Wrong UserName & Password
view adding But has helped establish a negative test attempt to failure conditions. In which wrong credentials are a failure condition.

* Keyword

This keyword is very special. This keyword defines the complete purpose of having Given, When, Then and the rest of the keywords. In Cucumber doesn’t care about Keyword use to explain test steps. it cares about what code it requires to execute for each step. That code-named a step explanation and we’ll discuss any of it within the next section. Now, remember that the keywords changed by the * keyword as well as the test will work fine.
Here we conclude the guide on different keywords of Cucumber. I am hoping you prefer it. Let’s now jump deep into how to put in place these steps by making use of Step Definition record.

Types of Gherkin keywords

We provide Types of Gherkin keywords in real time training. We offer classroom and project training for Selenium Training in Hyderabad.