Input your search keywords and press Enter.

How to set up Cucumber with Selenium for Automation testing?

We have learned all the aspects of Cucumber and Behaviour Driven Development and Testing as well. Today our prime focus is the implementation of Cucumber with Selenium. Cucumber is itself a kind of framework which makes testing processes efficient and systematic. So, if we combine Cucumber and Selenium altogether then automation testing becomes very powerful and it also improves the performance of the automation test pack.

Cucumber can be integrated not only with Selenium, but also, we use Cucumber with Watir and Capybara. If we talk about real-time application, then Cucumber is often used with Selenium Testing tool only. Thus, the agenda of this tutorial is understanding the use of Cucumber along with Selenium.

Let’s dive into the knowledge flow.

How to configure Cucumber with Selenium?

We firstly need to configure Cucumber and Selenium both to make compatible for each other. You just need to add some external JARs to your Selenium project. Here is the list of those JAR files-

  • Cobertura
  • Cucumber reporting
  • Mockito all
  • Selenium server standalone
  • Cucumber Junit
  • Junit

We have already discussed the steps to add these JARs. These Jar files are available to download from Maven repository site and SeleniumHq site.

If you are using Maven then you can create dependencies of above JAR files in a pom.xml file, instead of downloading and adding JARs to your Selenium project.

Click on below link to learn how to configure Cucumber in your project.

Steps to configure Cucumber with Selenium

You can also place these dependencies in your pom.xml

You need to add some plugins too-

How to create Feature file and Step definition for Selenium?

In our previous tutorial, we discussed Feature files creation and Step definition in the Cucumber framework. So, I would like to first suggest you read the previous tutorial-

Tutorial on Cucumber feature file creation and Step definition development

Feature file creation and Step definition are similar in Selenium as well.

Cucumber-Selenium Folder Structure

Here we need to understand the hierarchy of folder first. At first, we create a new package where all the Test steps class will be present. In our project, we created a package named Steps. Next, we create another folder where all the Cucumber feature files will be stored, and we name it as Resources/Features. Lastly, we create a Cucumber runner class where the command to integrate feature files and step definition will be written with respect to Selenium. Below image highlights the folder structure of Cucumber with Selenium.

Cucumber with Selenium folder structure

Test Scenario

We have a scenario where we first open Google and first validate the title of the page then we check whether search box is present or not.

Let’s convert above scenario to feature file with the help of plain English and Gherkin syntax.

Feature File

SearchEngine.feature

Now coming to its Step definition.

Step Definition

SearchEngineStepDefinition.class

Cucumber Runner Class

CucumberRunner.class

Run this runner class as JUnit Test.

This is all about cucumber set up with Selenium. You can ask your doubts via the comment form below.

 
Join Inviul fb group

Avinash Mishra is the author of Inviul blog. He is a software engineer and blogger by choice. He loves to write blogs, and apart from blogging, he is interested in documentary film making, listening to music, traveling around the world and philanthropic activities.

Leave a Reply

Your email address will not be published. Required fields are marked *