In this tutorial, you will learn about the cucumber testing tool. This tool is used for conducting user acceptance testing on every progression of software development. Due to its user-friendly interface, even a non-technical person can use this tool to test the software product.
What is cucumber in testing?
Cucumber is a software testing tool used for performing acceptance testing while the software is in the development stage. The technique of testing a software product when it is in the development stage is known as Behaviour-Driven Development.
Behaviour Driven Development (BDD) Framework
Behaviour Driven Development also known as BDD Framework is introduced to minimise the errors in the software testing process. This approach tells us to test every step in the development stage.
Behaviour Driven Development allows us to create the test scripts which are useful to determine whether the software Product is Successful or not. The test scripts are generated from both end-users and developers point-of-view. The test scripts and the code are developed concurrently.
If we are creating a registration form, then following test cases can be created, they are:
- The user can submit the registration form after filling the critical fields.
- The user cannot submit the registration form without filling the required fields.
When the code is ready, the tester will see whether the code passes these tests or not. The code is deployed only after executing the test cases successfully.
So, Cucumber is the tool which supports the Behaviour-Driven Development Framework.
Cucumber is a testing framework which reads the code written in simple English language and executes the test scripts.
What is Gherkin?
Cucumber executes the test scripts which are defined in a feature file. The language which is used for defining the test scripts is known as Gherkin. Gherkin assists the Cucumber in interpreting and executing the test scripts.
We know that BDD integrates different views while developing test scripts. To integrate different views, we require people from different groups, like developers, product owners, testers, project managers. As these people are not part of the same group, there is a possibility that they can use different terminology while developing the test scripts,
so, to avoid these problems, a common language called “Gherkin” is introduced. Gherkin gives a standard collection of Keywords, which is used by the people from different communities, and still, they will develop the same test scripts.
After learning about the Gherkin Language, now let us see some important terms present in it.
Subscribe to our youtube channel to get new updates..!
A Feature is defined as an Independent unit of a product or a project. For example, let us take Gmail, and we will see the features of this website.
- Creating and removing the mail accounts of the users.
- Users login feature for Gmail.
- Mail sending and receiving feature.
- File sharing feature through google drive.
- Users logout feature.
We can observe that the features mentioned above are independent of each other. In Cucumber, before developing the test scripts, first, we have to identify the features to be tested.
A feature includes the test cases under test for that feature. The feature file is used to save the feature, explanation of the feature and test cases of the feature under test.
It is suggested to write the description of the feature below the feature title so that it can be used for future purposes.
For every feature file, the extension is ‘.feature’.
Feature Files of Gmail Website
- For Account Creation Feature we will use “CreateAccount.feature”.
- For Account Removal Feature we will use “RemoveAccount.feature”.
- For Email Sending Feature we will use “SendEmail.feature”.
- For Email Receiving Feature we will use “ReceiveEmail.feature”.
The important keywords included in the Feature File are as follows:
- Feature: This keyword is used to indicate the feature under test.
- Test Case: This keyword is used to indicate the name of the test case.
- Given: Requirements for test case execution.
- When: Conditions which are to be satisfied with the successful execution of test cases.
- Then: What happens When the condition Present in the “WHEN” Clause is Satisfied.
Now let us study the scenario concept. The scenario gives us in-depth knowledge required for testing a particular functionality of a software product.
The Scenario is one of the essential parts of the Gherkins Structure. Each Scenario starts with “Scenario” Keyword. Every feature will have the number of scenarios and every Scenario will have the number of steps.
Scenario: Visit the About us page of a company’s website
The user will go to the company’s website.
He will click on the About us link, and he will get complete information about the company on that page.
For example, if we take the Netflix website, and we have to test the login functionality or feature of that website. But the problem here is, we have to see whether the login function is working for all types of subscribers. To do that we have to test the login functionality multiple times. For testing login functionality multiple times, we have to copy-paste the same steps multiple times, which is not a suitable method.
For achieving this, Gherkin introduced another structure called “Scenario outline”. The Scenario outline allows us to execute the same test scenario multiple times but with different input values. So, the login functionality is tested repeatedly by giving different inputs for “username” and “Password”. Cucumber executes the test repeatedly by changing the values of the input variables.
To handle multiple scenarios, another concept called “Tags” is introduced
In real-time, we may have several scenarios in a single feature. To handle such situations, Cucumber introduced the “Tags” concept. In the feature file, each Scenario will have a tag based on the purpose of the Scenario. So, we will select the Scenario based on the tag, and we will tell the Cucumber to test that Scenario.
While testing multiple scenarios, we will face a problem called code redundancy. To overcome that problem, cucumber adopted “Hooks” practice.
Hook enables us to handle the code workflow and assists us in reducing the code sacking. When we are executing multiple scenarios, we will set up and cleanup webdriver for every statement. To make the web driver setup and cleanup only once, we will use hooks.
To expand its reach, cucumber introduced the Junit framework.
Junit is a freeware testing framework used for testing the java code. Junit is essential in test-driven development, and it is a part of the unit testing framework. JUnit allows any non-technical person to execute the test cases smoothly. The execution flow in Junit will be as follows:
- Stakeholders will develop the feature file.
- According to the feature file, the step definition file is created.
- Junit runner class is specified for implementing the collection of test cases.
- Junit will integrate the test case result.
For software testing, Reporting and Documentation are essential.
Cucumber does not have any separate format for test reports. To get the format, we have to integrate the Cucumber with other freeware tools like Junit/Ant. We will take Junit because it supports java programs.
The pretty format creates the test reports in HTML format. The HTML format reports are more readable. After preparing the test reports, you have to store them in the following locations:
- Local Directory: We can save the test report in the directory in which we are executing the test scenarios.
- Server Directory: We can store the test report in any directory which is accessible by everyone.
To reduce the flaws in the testing process, cucumber does debugging of test scripts
In Cucumber, sometimes tests can fail due to unidentified reasons. The process of identifying the reasons for test failure is known as debugging. Debugging is done by installing Eclipse.
Advantages of Cucumber Framework
- It is an open-source testing tool.
- Plugins present in Cucumber work faster.
- Both developers and testers develop test Scripts with a mutual understanding.
- Cucumber Tool Supports programming Languages like Java, Ruby, Groovy, etc.
- It Supports Continuous Integration.
Cucumber is a freeware(open-source) testing tool used to conduct acceptance testing of the software code. It supports Behaviour-Driven Development to eradicate the failures in the software testing process. Cucumber tool can be used by a non-technical person to perform software testing. The Gherkin language used in the cucumber tool helps us accelerate the formation of test scenarios.