Create and Configure Cucumber Gradle Project
In this project we are going to use
Create Java Gradle Project using IntelliJ IDEA Community Edition
-
Open IntelliJ IDEA Community Edition
-
File >> New >> Project.
-
From left panel select Gradle and from right panel check the Java
-
From top of Project SDK it should select Java 13 or your version.
-
Press Next
-
From New Project panel
-
Name: Automation Tutorial (Please put your project name here)
-
Location: Save location
-
Click on Artifact Coordinates:
-
GroupId: com.hmtmcse.tutorial (Please put your domain name reverse)
-
ArtifactId: java-selenium-cucumber (Please put your id here)
-
Version: 1.0-SNAPSHOT (Let’s keep it as is.)
-
-
-
Click on Finish
-
You are successfully created the Gradle project.
Add Cucumber Dependencies and Configuration in Gradle
Package Name com.hmtmcse.tutorial, It’s important for our gradle config, please don’t forget the package name which you put in project creation.
We have to add 3 code blocks into build.gradle:
First
configurations {
cucumberRuntime {
extendsFrom testImplementation
}
}
Second: Add the cucumber dependency
project.ext {
cucumberVersion = '5.6.0'
}
dependencies {
testImplementation 'io.cucumber:cucumber-java:' + cucumberVersion
}
Third: Make sure you replaced the package name com.hmtmcse.tutorial
task cucumber() {
dependsOn assemble, compileTestJava
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['--plugin', 'html:reports/test-report', '--plugin', 'pretty', '--glue', 'com.hmtmcse.tutorial', 'src/test/resources']
}
}
}
Cucumber Options/Args
-
--plugin/-p: Specify the plugins which we want to add in project
-
pretty: It’s generate pretty report.
-
html: It means, it will generate the html types report in specific location.
-
-
--glue/-g: It’s specify project package name, and location of feature file(s)
How to find the build.gradle?
-
In your IntelliJ IDEA left side, find the panel named Project
-
Click on it and then look the files, you must will get the build.gradle.
-
You can also use shortcut, from keyboard press ctrl + shift + n
-
One popup will appear, from the popup select Files tab.
-
Then write build.gradle press enter, you will get the file.
Example build.gradle with all configuration.
apply plugin: 'java'
repositories {
mavenCentral()
}
project.ext {
cucumberVersion = '5.6.0'
}
dependencies {
testImplementation 'io.cucumber:cucumber-java:' + cucumberVersion
}
configurations {
cucumberRuntime {
extendsFrom testImplementation
}
}
task cucumber() {
dependsOn assemble, compileTestJava
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['--plugin', 'html:reports/test-report', '--plugin', 'pretty', '--glue', 'com.hmtmcse.tutorial', 'src/test/resources']
}
}
}