Tutorial 2 – Setup cucumber in eclipse
What you will Learn :
Cucumber-BDD Framework design flow
Create Maven project in eclipse
Download cucumber eclipe plugin
Delete the dummy packages
Add properties to pom.xml
Add dependencies to pom.xml
Add plugins to pom.xml
Update maven project
Cucumber-BDD Framework Design Flow
First, let us understand the flow that we would be designing in our cucumber framework. Look at the below figure. So basically, we would be given a document that would comprise of many functional requirements or user stories. So, this document would describe various requirements such as: how to perform a search for a particular product? how to add a product to a cart? and so on…
We would then convert or map this requirement to the respective feature file. The feature file would then be mapped to a step definition java file. Lastly, Testrunner java file would execute respective features. For each user story, we would write the corresponding feature file, step def file and Test Runner. So, memorize this design flow (user story > feature file > Step def java > Test runner java) while designing framework
Create Maven project in eclipse
Open eclipse, File >New >Project >Select ‘Maven Project’, see below
Click Next
Click Next. In the below window, type ‘maven-archetype-quickstart’ in the ‘Filter’ text field. Select the group id as shown below. It does not matter which version you see (here 1.1)
Click Next. Mention any desired ‘Group Id’ and ‘Artifact Id’. The name you mention in ‘Artifact Id’ would become the name of your maven project.
Click Finish
Wait for a minute or so. You should see a maven project getting created having the same name as ‘Artifiact Id’. See below
You should see the same folder structure that you see above
Download cucumber eclipe plugin
This plugin is very useful that will help us to create multiple feature files, it will highlight all the features/annotations in respective colors, the readability will be improved.
So just copy the url http://cucumber.github.io/cucumber-eclipse/update-site/
In the eclipse, Help > Install New Software
Paste the url in the ‘Work with’ field as shown below
Hit ‘Enter’ key
You would see a checkbox named ‘Cucumber Eclipse Plugin’ as seen below
Select the checkbox ‘Cucumber Eclipse Plugin’ as seen below
As soon as you select the checkbox, ‘Next’ button gets enabled as seen above
Click ‘Next’
After a minute or so, the below window would come up
Click ‘Next’
Accept the license terms
Click Finish
The s/w starts getting installed (see right hand side bottom screen of eclipse)
After sometime you will get below popup
Click ‘Install anyway’
After the installation, below popup comes up
Click ‘Restart Now’
Delete the dummy packages
Next, delete the 2 dummy packages that were created when maven project was created
So after deleting, the project folders looks as below
Add properties to pom.xml
Go to https://github.com/cucumber/cucumber-java-skeleton
This java skeleton is created by cucumber team. Scroll down the page, you would see pom.xml
Open pom.xml.
The below page would open, you would see some properties within the <properties> tag. As can be seen below, the jdk version is 1.8, junit ver is 4.13.1, cucumber version is 6.9.1
Copy all these properties
Open the pom.xml file in eclipse
Paste the properties in pom.xml
Save the xml
Add dependencies to pom.xml
Delete the dependency that is already present in pom.xml
So we have
Next, go back to the skeleton, you would see 3 dependencies
Copy these and paste it in pom.xml
Save the xml
Add plugins to pom.xml
Add a blank line before </project> tag
Now go to the skeleton and copy the entire <build> tag section, see below
Paste it at line#44 in pom.xml
Save the xml.
Expand ‘Maven Dependencies’ folder, see below. You would see that the various jars get downloaded automatically
Update maven project
Next, right click your project > Maven > Update Project
The below popup comes
Click OK. The project gets updated with jdk 8, see below
Close pom.xml file in eclipse.
So this is how we setup cucumber in eclipse.
Thank you for reading!