DEV Community

Cover image for Test Automation with Selenium and Cucumber
Vladislav
Vladislav

Posted on • Originally published at qamadness.com

Test Automation with Selenium and Cucumber

Selenium has been making huge strides in becoming the automated testing tool of choice for DevOps. Although it does require a degree of technical skill to setup and manage Selenium, it’s one of the most effective methods to automate testing on web browsers. Selenium is also able to integrate with other apps and tools to customize and streamline testing processes. But more recently, we’ve been hearing a lot of hype around the Cucumber tool.

Cucumber Selenium testing is fast becoming a popular combination for web application test automation. While Selenium is primarily used for regression and functional testing, the Cucumber testing tool allows you to write easy test cases that are executed by Selenium on different browsers.

Whether you employ a software testing company to manage your QA or you’re looking to implement new tools in-house, understanding the fundamentals behind different testing approaches will arm you with knowledge to make informed decisions.

Introduction to Cucumber

Introduction to Cucumber

Cucumber test automtion supports Behavior Driven Development (BDD), which is a technique where you write test cases in simple English sentences regardless of technical ability. In fact, anyone in the organization would be able to understand the test case requirements when written in Cucumber with Gherkin.

The Cucumber test framework incorporates explaining the application’s behavior using the Gherkin language. Gherkin uses a simple syntax and supports multiple programming languages like Java, Ruby, Python etc. so you can use whatever language you’re familiar with. The Cucumber automation tool not only integrates with Selenium but other web-based testing tools as well such as Ruby on Rails and Watir.

P.S. Cucumber is open source, so it’s free to install and download.

What is Behavior Driven Development (BDD)

Cucumber makes it easy to read and understand application flow.

With Behavior Driven Development (BDD), the test scenarios are created before the code is developed. This defines the expected behavior of the system from the user’s perspective and what they want to achieve with the application.

Cucumber is the link between business analysts, non-technical and development resources. Because you don’t need coding experience to write test cases, anyone who understands the application’s logic can contribute to the test process.

Cucumber and Selenium

Why Cucumber and Selenium?

The Cucumber framework in Selenium allows running automated acceptance tests developed in a BDD format. One of its best features is being able to interpret plain-text descriptions.

Cucumber Selenium testing is run using the tests written in Feature Files, which are non-technical and easy to understand. So, Selenium is actually the testing framework and Cucumber is the BDD tool to test at the user interface layer.

A basic Cucumber test case example is testing a login page that’s based on the following actions:

  • Given I am on the login page
  • When I enter valid credentials
  • Then I should see my account

Cucumber can leverage skills as expertise differs between team members. Some testers could be highly technical, while in the same team, other testers may have little or no technical skill. Regardless of level, every person in the team can still participate in developing automation tests from tests based on business logic and workflow to creating objects and calls, and defining data sources.

Setting up test cases in Selenium can require more programming knowledge whereas Cucumber allows anyone who can read English to write a test case for the web app’s interface. Selenium is an open-source automation testing framework mainly developed on Java. It interacts with the browser interpreting the test instructions from Cucumber.

Differences between Selenium and Cucumber

Differences between Selenium and Cucumber

  • Selenium is a browser automation testing tool and Cucumber is as a testing tool based on BDD.
  • Selenium test scripts are written in Java, C#, etc. Cucumber test scripts are written in English text using Gherkin language syntax and is more like documenting procedures.
  • You can use conditional statements in Selenium but not in Cucumber.
  • Selenium automates UI testing on browsers while Cucumber enables BDD so you can write the scenarios first starting with the business team.

In Summary

Cucumber and Selenium are both free and available for download. Integrating Cucumber with Selenium leverages skills in DevOps and across business areas for a BDD approach for UI testing. Selenium automates cross-browser testing so having this combination can improve the DevOps CICD process, expedite testing and involve those with more business knowledge.

Automated testing has become essential in reducing repetitive and manual tasks and maintaining software quality. And, because Selenium offers automation, security, usability, and performance, more and more QA testing companies are choosing to go with Selenium to get the advantage on software testing.

Behavior Driven Development is also getting more attention to test important user scenarios with more business input. This approach defines the expected behavior of a feature in plain English text. BDD supports communication between development and business so everyone has a shared understanding of what needs to be developed.

Top comments (0)