In DevOps, automation is achieved using different tools. The most important Phase which needs automation in DevOps is “Testing”. Today lets looks at few of the tools which aid us in automating Testing cycle.
The important as point to note here is “Testing” can happen in many different ways, and that is the reason you will find many tools which help in automating different testing aspects. Let’s us understand Cucumber which is most famous tool for automating Behavior Driven Testing.
Cucumber is a tool based on Behavior Driven Development (BDD) framework which is used to write acceptance tests for web application. It allows automation of functional validation in easily readable and understandable format (like plain English) to Business Analysts, Developers, Testers, etc.
Cucumber feature files can serve as a good document for all. There are many other tools like JBehave which also support BDD framework. Initially Cucumber was implemented in Ruby and then extended to Java framework. Both the tools support native JUnit.
Behavior Driven Development is extension of Test Driven Development and it is used to test the system rather than testing the particular piece of code. We will discuss more about the BDD and style of writing BDD tests.
Cucumber can be used along with Selenium, Watir, and Capybara etc. Cucumber supports many other languages like Perl, PHP, Python, .Net etc. In this tutorial we will concentrate on Cucumber with Java as a language.
Basic components of Cucumber are:
#1) Feature Files:
Feature files are essential part of cucumber which is used to write test automation steps or acceptance tests. This can be used as live document. The steps are the application specification. All the feature files ends with .feature extension.
Sample feature file:
Feature: Login Functionality Feature
In order to ensure Login Functionality works,
I want to run the cucumber test to verify it is working
Scenario: Login Functionality
Given user navigates to worldofagile.net
When user logs in using Username as “USER” and Password “PASSWORD”
Then login should be successful
Scenario: Login Functionality
Given user navigates to worldofagile.net
When user logs in using Username as “USER1” and Password “PASSWORD1”
Then error message should be thrown
#2) Feature:
This gives information about the high level business functionality (Refer to previous example) and the purpose of Application under test. Everybody should be able to understand the intent of feature file by reading the first Feature step. This part is basically kept brief.
#3) Scenario:
Basically a scenario represents a particular functionality which is under test. By seeing the scenario user should be able to understand the intent behind the scenario and what the test is all about. Each scenario should follow given, when and then format. This language is called as “gherkin”.
Given: As mentioned above, given specifies the pre-conditions. It is basically a known state.
When: This is used when some action is to be performed. As in above example we have seen when the user tries to log in using username and password, it becomes an action.
Then: The expected outcome or result should be placed here. For Instance: verify the login is successful, successful page navigation.
Background: Whenever any step is required to perform in each scenario then those steps needs to be placed in Background. For Instance: If user needs to clear database before each scenario then those steps can be put in background.
And: And is used to combine two or more same type of action.
What is difference between tool – Cucumber and Selenium?
Let’s see what is the differences Between Selenium v/s Cucumber.
Selenium is an open-source – software automation testing tool. Selenium is mainly used for functional testing of web applications as against Cucumber which is also testing tool but it focuses on Behavior Driven Development (BDD) framework. Cucumber defines behavior for persona in the application in plain meaningful English text. This simple language used for recording behavior is called Gherkin.