There are two ways of testing: manual testing and automation testing. Manual testing is testing with manual effort by using mouse, keyboard, tablet, mobile. Automation testing is testing with scripted sequences that are executed by testing tools. Automation testing mostly focuses on regression testing, which is testing previously implemented functions over and over again to ensure they still work as new updates and functions are deployed.
There are many automation frameworks out there. Below are the differences among three of the most common frameworks:
Behavior-Driven Development (BDD): Development and testing concentrate their efforts on business requirements and needs.
Test-Driven Development (TDD): QA discusses with development how to test. Development will build application based on the testing process agreed to.
Acceptance Test-Driven Development (ATDD): Development and testing focus on acceptance by the end user.
Various tools have been developed to assist with automation testing. For this article, we will look at the Selenium application programming interface (API) combined with the Cucumber BDD tool.
Selenium acts as an intermediary between automation code and web applications that open the browser and interact. In other words, Selenium drives the browser.
Cucumber is a software tool that supports BDD frameworks. It was originally written in the Ruby programming language. It supports different languages like Java, .NET, and Ruby. It focuses on the business logic or behavior (requirements). It is easy to understand by non-technical persons, as well as easy to track or maintain code coverage between automation code and feature file (manual test case).
A BDD framework with Cucumber has three components: Feature file, Step definition, & Runner file.
Feature file is the manual test cases. A feature file has the following components.
Feature: What to test.
Description: Write some important requirement/need (this is an optional field).
Background: Write any common steps here (this is an optional field).
Scenario/Scenario Outline: Detail steps on how to test using Gherkin language (Given, When, & Then statements).
Given → Setup/Pre-action
When → Action (actual testing)
Then → Validation
And/Or → Same steps multiple
An example of a simple Feature file for Facebook login test
All the coding that is required to run the feature file are located in the step definition file.
The runner file runs the Cucumber feature file and step definition file by using multiple options. Some of the options are:
dryRun: Checks if all the steps in the feature file have the step definition.
features: The paths of the feature file(s).
glue: The paths of the step definition files.
tags: What tags in the feature file should be executed.
monochrome: Display the console output in much readable way.
format: What all report formatters to use.
strict: Will fail execution if there are undefined or pending steps.
The runner files of different feature files can be entered in a TestNG xml suite to run all the test cases at the same time.
In conclusion, using Cucumber with Selenium is a relatively straightforward and highly effective way to conduct BDD.