Working with Gherkin Syntax in Opkey

Opkey gives you a feature to create test cases using the Gherkin language. It is a language used to define scenarios in a structured and understandable manner. It is not just for developers; it is designed to bridge the gap between technical and non-technical team members.

Key features of Gherkin code

  1. Readability: Gherkin scenarios are written in a natural language format, making them accessible to both technical and non-technical team members.
  2. Collaboration: Gherkin promotes collaboration among team members by providing a common language for discussing and documenting software behavior.
  3. Maintenance: Gherkin scenarios are easily maintainable. Changes in requirements can be reflected in scenarios without major modifications to the underlying code.


Structure of Gherkin:

  • Feature: It describes what a specific feature or functionality of the software is supposed to do.

  • Scenario: Each scenario outlines a particular use case or instance related to the feature being tested.

  • Given, When, Then:

    • Given: Describe the initial setup or context for the scenario.

    • When: Specifies the action or event that takes place.

    • Then: Define the expected outcome or result after the action.


Gherkin syntax

Gherkin syntax is a structured language used for writing human-readable descriptions of software behavior, often in a behavior-driven development (BDD) context. 

Let's see an example of the Gherkin Code,

Each element in Gherkin syntax plays a crucial role in outlining the behavior of the software in a human-readable and structured manner, fostering collaboration and understanding among team members involved in the software development process.

Let's break down the significance of each element :

  1. FEATURE - It defines the high-level functionality or feature being tested.

  1. SCENARIO - Represents a particular test scenario within the feature.

  1. GIVEN - Sets up the initial state or precondition for the scenario.

4. WHEN - Represents an action or event that occurs.

5. THEN - Describe the expected outcome or result after the action.

6. AND/BUT- Helps to add additional conditions or steps within a scenario.


How to build up a Gherkin Test Case?


To create a Gherkin test case, hover over the opkey launchpad and select the continuous opkey automation” portal.

Here you have to click on the “launch here” button and you will be asked to select your project. 

Select your project and you will be redirected to your project workspace. Create a folder in your workspace and right-click to select the Gherkin feature Or you may "Click to Create New Artifact"


Now give a name and description to your gherkin test case and then click on the ok button.

Now you will be redirected to the gherkin window. 

Here in this window you can write the code you want to execute.

Let's take an example -

Suppose you want to verify the user authentication process with valid and invalid credentials.

So you will write the code as shown below in the screenshot:-

  • Here, The Feature section describes the high-level feature, which is user authentication.
  • The first Scenario outlines the steps for verifying user authentication with valid credentials.
  • The second Scenario outlines the steps for verifying user authentication with invalid credentials.

Once you are done with the code, the next step is to link the steps with the function library. 

Create a function library that contains the actual logic for the steps implemented in your step definitions. 

For instance, in this case where your Gherkin scenario describes the steps for user authentication, the associated code (step definitions) will contain functions to interact with the system under test, such as entering credentials, validating them, and checking the login status.

So linking the steps with the associated function library is essential as it will be responsible for the actual implementation of the steps and execution of the tests written in Gherkin. 

Right-click on the specific step to link it with the related function library.

Now select the specific function library and click on the select button. To learn how to create a function library click Working with function libraries

Now Next step is to save the gherkin code by using the save icon as shown below.

Now you can execute your gherkin test case by using the run now icon. When you run the test case, it will execute the associated functions for each step.

Now select the execution agent and plugin and click on the finish button to start executing your test case.

Now as soon as the execution is finished, you can view your test result by clicking on the icon as shown below in the snapshot.


To work with BDD ( gherkin stories) click on using BDD gherkin stories.

Explore more features of  Opkey by clicking  Here








Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article