Automation Kotlin Gradle Cumber:未定义的步骤

Automation Kotlin Gradle Cumber:未定义的步骤,automation,cucumber,Automation,Cucumber,我正在使用cucumber和kotlin构建一个selenium自动化项目,但是在我设置了框架之后。cucumber无法识别这些步骤。我主要打电话给终端上的GradleCumber开始测试 格雷德尔先生 plugins { id 'java' id 'org.jetbrains.kotlin.jvm' version '1.3.21' id "com.github.spacialcircumstances.gradle-cucumber-reporting" versio

我正在使用cucumber和kotlin构建一个selenium自动化项目,但是在我设置了框架之后。cucumber无法识别这些步骤。我主要打电话给终端上的GradleCumber开始测试

格雷德尔先生

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
}
结构如下: 结果如下:

 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


我可以在按住ctrl键并单击已实现的给定步骤时或在执行步骤时导航到步骤文件。它运行时似乎找不到步骤定义。我做错了什么?

我有一个确切的问题,上面的答案是正确的,但有点不清楚。(我删除了所有其他内容,而不是将资源文件夹也留在那里!)

这是我的
build.gradle
文件的
task()部分:

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']
        }
    }
}
其中,
helloccumber
是我的包名,如中所述


我希望有帮助

您的glue
src/test/kotlin/steps
应该是一个包名,所以只需
steps