Search code examples
javatestinggradlecucumbercucumber-java

Unable to run cucumber feature file using gradle in Eclipse. I am getting "Error: Could not find or load main class cucumber.api.cli.Main" error


I am trying to run cucumber feature file on Eclipse but getting following error. "Error: Could not find or load main class cucumber.api.cli.Main"

Gradle code (build.gradle)

apply plugin: 'java'

configurations {
    cucumberRuntime {
        extendsFrom testRuntime
    }
}

task cucumber() {
    dependsOn assemble, compileTestJava
    doLast {
        javaexec {
            main = "cucumber.api.cli.Main"
            classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
            args = ['--plugin', 'pretty', '--glue', 'gradle.cucumber', 'src/test/resources']
        }
    }
}

dependencies {
    testCompile 'io.cucumber:cucumber-java:3.0.2'
    testCompile 'io.cucumber:cucumber-junit:3.0.2'

    testCompile 'junit:junit:4.12'
}

repositories {
    mavenCentral()
}

Feature file (add.Feature)

@tag
Feature: Title of your feature
  I want to use this template for my feature file

  @tag1
  Scenario: Title of your scenario
    Given I have the calculator
    When I enter input1 and input2
    And I press add button
    Then I get output

I am right clicking on feature file. Then selecting run as and pressing on cucumber feature. Thanks in advance.


Solution

  • I forgot to add runner class. Below is the code for runner class. After adding this class, I am able to run the feature file

    runcukestest.java

    package cucumber;
    
    import cucumber.api.junit.Cucumber;
    import org.junit.runner.RunWith;
    import cucumber.api.CucumberOptions;
    
    @RunWith(Cucumber.class)
    @CucumberOptions(plugin = {"pretty"})
    public class runcukestest {
    
    }