Reputation: 41
I am building a selenium automation project using cucumber and kotlin, but after I have set up the skeleton. The steps can't be identified by cucumber. I mainly call gradle cucumber on terminal to begin the test.
build.gradle
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.21'
id "com.github.spacialcircumstances.gradle-cucumber-reporting" version "0.1.7"
}
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
jcenter()
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testCompile group: 'junit', name: 'junit', version: '4.12'
testImplementation 'io.cucumber:cucumber-java8:4.7.1'
testImplementation 'io.cucumber:cucumber-junit:4.3.1'
implementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59'
testImplementation 'no.tornado:tornadofx:1.7.17'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
configurations {
cucumberRuntime {
extendsFrom testImplementation
}
}
task cucumber() {
dependsOn assemble, compileTestJava
doLast {
javaexec {
main = "cucumber.api.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.test.output
args = ['--plugin', 'json:test_reports/' + getDate() + '_automation_test_result.json', '--glue', 'src/test/kotlin/steps', 'src/test/resources/feature']
}
}
}
cucumberReports {
outputDir = file('test_reports/' + getDate()+ '_html')
buildId = '0'
reports = files('test_reports/' + getDate() + '_automation_test_result.json', 'test_reports/cucumber-json.json')
}
static def getDate() {
def date = new Date()
def formattedDate = date.format('yyyy-MM-dd')
return formattedDate
}
Below is the structure: This is the folders Below is the result:
Task :cucumber
Sep 18, 2019 5:27:40 PM cucumber.api.cli.Main run
WARNING: You are using deprecated Main class. Please use io.cucumber.core.cli.Main
Undefined scenarios:
src/test/resources/feature/test.feature:15 # Input something in the search bar
src/test/resources/feature/test.feature:16 # Input something in the search bar
src/test/resources/feature/test.feature:25 # Change to different sub-page
src/test/resources/feature/test.feature:26 # Change to different sub-page
src/test/resources/feature/test.feature:27 # Change to different sub-page
src/test/resources/feature/test.feature:28 # Change to different sub-page
6 Scenarios (6 undefined)
30 Steps (30 undefined)
0m0.100s
You can implement missing steps with the snippets below:
Given("I have logged in as a super admin", () -> {
// Write code here that turns the phrase above into concrete actions
throw new cucumber.api.PendingException();
});
Given("I have navigated to CRM", () -> {
// Write code here that turns the phrase above into concrete actions
throw new cucumber.api.PendingException();
});
Given("I have clicked the client button on the navigation bar", () -> {
// Write code here that turns the phrase above into concrete actions
throw new cucumber.api.PendingException();
});
When("I input {string} in the search bar", (String string) -> {
// Write code here that turns the phrase above into concrete actions
throw new cucumber.api.PendingException();
});
Then("the search result should contain {string}", (String string) -> {
// Write code here that turns the phrase above into concrete actions
throw new cucumber.api.PendingException();
});
Given("I have navigated to the home page on CRM", () -> {
// Write code here that turns the phrase above into concrete actions
throw new cucumber.api.PendingException();
});
When("I click the {string} on the navigation bar", (String string) -> {
// Write code here that turns the phrase above into concrete actions
throw new cucumber.api.PendingException();
});
Then("I should be brought to different page", () -> {
// Write code here that turns the phrase above into concrete actions
throw new cucumber.api.PendingException();
});
BUILD SUCCESSFUL in 2s
4 actionable tasks: 1 executed, 3 up-to-date
I can navigate to the step file when I ctrl+click on the implemented Given or When steps. It seems it can't find the steps definition when it runs. What am i doing wrong here?
Upvotes: 1
Views: 1357
Reputation: 911
I had this exact issue and the answer above is correct, but a bit unclear. (I removed everything else rather than leaving the resources folder in there too!)
This is the task cucumber()
section of my build.gradle
file:
task cucumber() {
dependsOn assemble, compileTestKotlin
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['--plugin', 'pretty', '--glue', 'hellocucumber', 'src/test/resources']
}
}
}
where hellocucumber
is my package name, as outlined in this example.
I hope it helps!
Upvotes: 2