Configure Cucumber Setup in Eclipse and IntelliJ [Tutorial]
Here's how to start using Cucumber, the widely used BDD framework for Selenium automation testing. This article helps you get set up in Eclipse and IntelliJ IDEA. It also provides a step-by-step guide on setting up Maven Cucumber project in Eclipse.
Join the DZone community and get the full member experience.Join For Free
Selenium is a test automation framework extensively used by organizations looking to expedite the web-product testing process. As far as test automation frameworks in Java are concerned, TestNG is largely preferred by QA engineers for the development and enhancement of test suites. With the adoption of Agile methodology in the work environment, a diverse set of stakeholders like QAs, technical managers, and program managers — including non-technical team members — are willing to work collaboratively for the betterment of the product.
The project lifecycle includes the business analysts and other stakeholders testing the application in a thorough manner. This is where the necessity to incorporate Behavior Driven Development (BDD) comes into the picture. Cucumber is a popular BDD tool that is widely used for test automation.
In the first article of the Cucumber Selenium tutorial series, we will see how to set up Cucumber in Eclipse and IntelliJ for automated browser testing.
If you are already familiar with Selenium with Java, you can also check our TestNG tutorial.
What Is Cucumber Framework in Selenium?
Cucumber is a Behavior Driven Development (BDD) framework used for automated browser testing. It enables diverse project stakeholders to come up with test scenarios that are written in plain English. This encourages participation from team members that do not come from a technical background.
This simple text uses Gherkin language which can be easily understood by technical and non-technical people alike. Cucumber is written using the Ruby programming language but it supports other popular languages like Java, Python, and more.
Advantages of Cucumber Framework
Though there are a number of BDD tools like SpecFlow, Behave, and so on, Cucumber for Selenium automation is the most popular of them all.
Here are the major reasons why QA engineers prefer Cucumber over other BDD frameworks:
- Technical and business teams can participate in test scenario development since the tests are written in plain and simple English.
- No prior coding experience is required to come up with test scenarios in Cucumber Selenium. Even a manual tester with zero exposure to coding can be a part of Cucumber framework creation.
- It helps in the creation of modular and reusable code.
Now that we have covered the basics of the Cucumber framework, let’s look at how to setup Cucumber in Eclipse. In this IntelliJ Cucumber tutorial, we would also cover setting up Cucumber for IntelliJ and using Cucumber with Maven. Here are the pre-requisites for installing the Cucumber framework:
- Install Java
- Install Eclipse IDE for Java or Install IntelliJ
- Install Maven
- Install Selenium WebDriver
- Install JUnit
- Install Cucumber
Once you are done with all the installations mentioned above, you can now proceed with Cucumber setup in Eclipse and IntelliJ (i.e., IDE of your choice). We will cover IntelliJ setup with Cucumber in the IntelliJ Cucumber tutorial section of this article.
How to Configure Cucumber in Eclipse
In this section, we will see how to add relevant JARs to a Java project so that you can setup Cucumber in Eclipse. In case you have already worked with the TestNG framework, follow the same procedure for adding required Jars to the project. In case you are just getting started with Selenium automation testing, you may follow the below steps for realizing Cucumber setup in Eclipse:
Open the Eclipse exe by double-clicking on the same. If you are opening it for the first time you will get an option to select the workspace where all the created projects will be saved.
You can change your workspace directory anytime by using the Browse button. Since I already had a workspace, I got the following screen:
Click on the Launch button and you will see the Welcome window of Eclipse. You may close this window since it not required to setup Cucumber in Eclipse.
The next step is to create a Project. Navigate to File > New > Java Project for creating a new project.
Next, you will see a window to enter your project name. Give a name to your project and click on the Finish button.
You will now be able to see your project in the Project Explorer window.
Now that the project is ready, it’s time to add the relevant Cucumber and Selenium JARs to your project. I have already downloaded the Selenium and Cucumber JARs since these JAR files are required for to setup Cucumber in Eclipse.
Right-click on the Sample Project in the project explorer and navigate to Build Path > Configure Build Path.
Now click on Add External JARs button.
Browse to the location where you have downloaded the JAR files and select the downloaded Cucumber JARs and click Open.
Similarly, add all the Selenium JARs required for completing the Cucumber setup in Eclipse. Upon adding, you will see the JARs under the Libraries tab.
Finally, click on Apply and Close. With this, you have successfully imported the JARs required to setup Cucumber in Eclipse. The imported JARs will be visible under the "Referenced Libraries" tab of the project.
How to Install Cucumber in IntelliJ
Now that we have setup Cucumber in Eclipse, let’s look at how to configure Cucumber with IntelliJ (another popular IDE for Java development) in this section of IntelliJ Cucumber tutorial. Here are the steps to configure Cucumber in IntelliJ.
Launch the IntelliJ IDE and navigate to File > New > Project.
Select Java and click on Next until you arrive on the following screen:
Give a name to your project and click on Finish.
You will get a prompt to open the project in the same window or a new window. You can select "This Window."
You will see the project getting displayed in the project explorer.
Import the required JARs for Selenium and Cucumber, similar to how it was done with Cucumber setup in Eclipse. To do so, navigate to File > Project Structure > Modules.
As highlighted in the above screenshot select the Dependencies Tab. Add the required dependencies by clicking on the "+" sign towards the bottom and select the required JARs (or Directories).
Select the JARs through the "browse menu" and click on OK.
On similar lines, add the Selenium JARs. With this, the Cucumber Selenium dependencies are added to the project. Click on Apply and then press OK.
Like Cucumber setup in Eclipse, the imported JARs will be available under the "External Libraries" section.
Now that we have covered the aspects related to IntelliJ and Cucumber in IntelliJ Cucumber tutorial section, let’s move to the next section of this Cucumber Selenium tutorial.
In the Maven tutorial, we saw how Maven eases the project configurations as the dependencies can be added directly in the project’s pom.xml. Maven will directly import the required jars once you specify them in the pom.xml. With this approach, you can do away with the manual addition of jar files to the test automation project.
How to Create Cucumber Maven Project in Eclipse
We will be using Cucumber setup in Eclipse (using Maven). The steps mentioned in the IntelliJ Cucumber tutorial section still remain the same. Hence, you can use either of the IDEs as per your convenience. This is the primary reason why we covered these two IDEs in this introductory blog of the Cucumber Selenium tutorial series.
Navigate to File > New > Project.
From the dialog, expand Maven, select Maven Project, and click on Next.
Select the checkbox to Create a Simple Project and click on the Next button.
Enter the details like the Group and Artifact ID, and click on the Finish button.
You will see your Maven project under the project explorer.
Pom.xml will contain package information for resolving the Cucumber and Selenium dependencies.
Click on the pom.xml tab at the extreme right. You will see an XML file that contains all the project details.
Fetch the maven dependencies from the Maven Repository and add the dependencies manually in pom.xml. Shown below is an example pom.xml where we added the required dependencies from the Maven repository:
Save the project, and here you go. Your Maven project is all set to be used to run Cucumber tests using Selenium WebDriver. In the next article of the Cucumber Selenium tutorial series, we will demonstrate how to write Cucumber tests for automated browser testing.
Cucumber is one of the widely used BDD frameworks for performing automation testing. The major advantage of a BDD framework like Cucumber is that diverse set of team members can participate in creating impactful test scenarios. Along with Cucumber setup in Eclipse, we also covered setting up Cucumber in IntelliJ in the IntelliJ Cucumber tutorial section of this blog.
In our first article of the Cucumber Selenium tutorial series, we took a deep dive into how to configure Cucumber and Selenium WebDriver with Eclipse. We also had a look at setting up Selenium WebDriver and Cucumber with IntelliJ IDEA IDE. In order to avoid manual addition of jar files to the project. This is where Selenium with Cucumber using Maven can be super helpful as the Cucumber Selenium dependency is added to the project pom.xml file. Now that we have covered the configuration aspects related to the Cucumber framework, we will look into the implementation aspects in subsequent articles.
Published at DZone with permission of Harshit Paul, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.