Cucumber is an automation tool based on Behavior Driven Development (BDD) framework which is used to write tests for a web application. It allows users such as Business Analysts, Developers, Testers, etc. to automate the functionality in an easily readable and understandable format (like plain English).
Let us explore more about this automation tool.
Requirement of the Cucumber Test Automation Tool
There was a need to get rid of the ambiguity and make everything connect to the entire software development lifecycle. Thus, the development process required something that expands the customer’s acceptance criteria to the actual development and testing process. So the idea was to upgrade the existing TDD (Test-Driven Development) process and join the following acceptance tests, functional requirements and software documentation into one arrangement that would be reasonable to non-technical people as well as test automation tools.
Introduction to Cucumber
You cannot simply download the Cucumber like other test automation tools, and start coding and automating your test cases. There is a process needed to make full use of Cucumber which is known as Behavior-Driven Development (BDD).
In this process, there are three main people involved. One, who manages the prerequisites like a Business Analyst or a Product Owner. Second, an individual who designs executes and creates it like a developer. The third primary person is the one who is going to test and guarantee it.
These key people examine the feature which has to be implemented and discuss various use cases and how the system needs to carry on at different point of time in different situations. Further, these practices are noted down as scenarios which become the written document of how the system has to behave in various cases.
Language And Platform Compatibility
Cucumber Implementation is available in open source languages like Python, PHP, Java, Ruby, etc.
Framework Integration: Cucumber is integrated and supported by frameworks like Waitr, Capybara, Ruby on Rails, Selenium, etc.
To understand Cucumber, we have to know each of its features and usages. These are described below.
1. Feature Files:
These are the typical test case files in a BDD process and furthermore, go about as living document to the business necessity and a bridge between the requirement documentation and implementation part of it.
The syntax/format in which these feature files are written is called Gherkin; this provides with an arrangement of guidelines which should be taken after composing your feature file. These files should have an extension ‘.feature.’
Scenario: The description following this keyword gives the expectation of this test case or scenario, as to what is being checked and in what conditions. To make a scenario more readable, Gherkin offers a few keywords which you can likewise call as clauses.
Given: Given condition speaks to the pre-conditions required for the specific situation and if your situation requires more than one pre-condition, “AND” clause can be used immediately after the ‘Given’ condition.
When: Any statement that begins with ‘when’ clause represents the steps-to-execute part of the test case document. It contains the executions steps that are specific to this scenario. In the majority of such circumstances, this section contains more than one step and hence along with this clause we also use the AND clause as well.
Then: Any statement that starts with this clause represents the verification steps and the expected result of the scenario. On the off chance that this part likewise contains multiple steps, then AND clause is used alongside.
Configure Java Environment for Cucumber Execution:
- JAVA – Install the latest (Java Development Kit) JDK on your machine.
- Eclipse –
a) IDE that we will use to write our feature files and all the code behind.
b) When it starts up, choose a workspace.
c) Click on Help–Install New Software, Add plug-in from http://cucumber.github.com/cucumber-eclipse/update-site
- Download the Cucumber Jars mentioned below, from Online Maven Repository, click here.
- Download Selenium Standalone Server, here.
- Create a new Java project in Eclipse, and add all downloaded External Jars to Java build path
Running your first Test Scenario:
The steps below, represent one of the scenarios that are present in your feature file called Registration.feature
As a user
I want to be able to add new clients in the system
So that I can add accounting data for that client.
Sign up a new user
Given the user is on landing page
When he chooses to new user
And he provides the first name as Tester
And he provides the last name as Jenkins
And he provides the email as firstname.lastname@example.org
And he provides the password as password
And he provides the confirm password again as password
And he signs-up
Then he should be logged in to the application
The code representing the above steps in Java is called the Glue Code. A certain format of a regular expression is used to match the steps with their respective Glue Code.
The same implies to the other statements irrespective of the clause/keyword used. Put the above-represented code in .java file inside a class, for example, consider the file name as StepsDefinitions.java.
Pretty Format (HTML Report)
Pretty Format produces the Cucumber test report in the HTML design, i.e. an HTML record. It is the most readable report design
Create a runner class file.
- Create a runner class named cucumberTestRunner.java inside the package.
- Write the following code. Save the file.
Run the test using option.
- Select cucumberTestRunner.java file from package explorer.
- Right-click and choose the option, Run as
- Select JUnit test
After execution, under target directory, a folder named as Destination will be created. You will be able to see the execution report named as “Index.html.”
Successful automation does not depend on tools entirely. It is dependent on the standard testing processes, the right test team roles, duties and skills as well. Tools, processes and test teams are the three essential legs of the test automation tool.
Hope this answers your basic queries on how to use Cucumber as an automation testing tool.