Home / Tutorial /Installing Cucumber...
Srinivasan G
2024-01-04
0 mins read
The functionality of the cucumber is abstracted out in jars and to execute a Cucumber test
using Java in Eclipse, you need various Cucumber jars or modules.
There are various ways to download Cucumber jars for Eclipse; choose one from the alternatives
listed below:
We will talk about Downloading Cucumber Jars from Maven dependencies
Download Cucumber Jars from Maven dependencies
The most popular and efficient method of configuring cucumber with eclipse is downloading Cucumber Jars from Maven dependencies. But those who are unfamiliar with Maven may find this to be somewhat challenging and end up losing a lot of time. Few conditions must be met in order to configure cucumber in eclipse.
Navigation flow: File->New->Others->Maven project.
The user needs to type the name of the Project folder in a new window that appears. Below is a screenshot for the same.
Click on Maven Project > Next
Select the Checkbox to create a simple project > Next
User need to give Group id Name And Artifact id Name > Finish
Observe the package Explorer > POM.xml
By default, pom.xml will be generated like this:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>DLA_CucumberJava</groupId> <artifactId>DLA_CucumberJava</artifactId> <version>0.0.1-SNAPSHOT</version> </project>
The next step is to add cucumber dependencies to the project once Maven has been installed on Eclipse and a Maven project has been created.
Add the below dependency to pom.xml
<dependencies> <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java --> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-java</artifactId> <version>7.8.1</version> </dependency> </dependencies>
Below dependencies will get added after successful build.
Let's make a good folder structure for the project before moving on to write the first script.
Create a new Package by right-click on the src/test/resources folder and select New > Package.
A new pop-up window will open. Specify the name as DLA_Feature and click on Finish.
Now the folder structure will look like:
Create a new file under DLA_Feature folder:
A pop-up window will open.
Provide the file name as DLA_Login.feature and click on Finish.
1. Go to Help menu in Eclipse IDE and click on “Eclipse Market Place”.
2. Add the cucumber eclipse plugin.
After successful installation of Cucumber Eclipse plugin, feature file will look like this:
Adding steps in created feature file:
Right click on Feature file and run as Cucumber Feature:
It will give the below message in Console to write the missing steps:
Create new folder under src/test/java and name it as Step_Definitions.
Follow the below steps to create a new folder:
Create new class file under Step_Definitions folder and name it as DLALoginSteps and click on Finish.
Copy the missing steps from Console and paste it in DLALoginSteps file:
You can write your code in the Step Definition file for further implementation.
Add the below dependency in pom.xml to run the tests as JUnit test.
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> <scope>test</scope> </dependency>
Adding Cucumber JUnit Dependencies on POM.xml file.
<dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-junit</artifactId> <version>7.8.1</version> <scope>test</scope> </dependency>
By right-clicking the "src/test/java" package and choosing New > Class, create a new Class file with the name "Test Runner" in it. This class only requires annotations to make it clear that cucumber features will be processed through it, and you can specify which feature files to pick up in addition to the location of the steps package.
Add the below lines of code in Test Runner class:
package Step_Definitions; import org.junit.runner.RunWith; import io.cucumber.junit.CucumberOptions; import io.cucumber.junit.Cucumber; @RunWith(Cucumber.class) @CucumberOptions( features = "src\\test\\resources\\DLA_Feature" ,glue={"stepDefinition"} ) public class TestRunner { }
INQUIRY
By tapping continuing, you agree to our Privacy Policy and Terms & Conditions
SkillAhead Solutions
Gurgaon
USA
1603, Capitol Avenue, Suite 413A, 2659, Cheyenne, WY 82001, USA
`Copyright © DevLabs Alliance. All rights Reserved`
|
Refund & Reschedule Policy
Privacy Policy
Terms of Use