Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
208 views
in Technique[技术] by (71.8m points)

java.lang.NoSuchMethodError: cucumber.api.CucumberOptions.snippets while running Cucumber Tests with Karate Dependencies

I have run into an issue where I am trying to create Karate Tests in my Cucumber Project.

Here is how my Pom file looks:

        <?xml version="1.0" encoding="UTF-8"?>
    <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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.test.automation</groupId>
        <artifactId>testautomation</artifactId>
        <version>1.0-SNAPSHOT</version>
        <properties>
            <failsafe.fork.count>1</failsafe.fork.count>
            <java.version>1.8</java.version>
            <maven.build.timestamp.format>yyyy-MM-dd-HHmm</maven.build.timestamp.format>
            <cucumber.version>1.2.5</cucumber.version>
            <selenium.version>3.0.1</selenium.version>
            <karate.version>0.9.2</karate.version>
        </properties>        
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.6.0</version>
                    <configuration>
                        <encoding>UTF-8</encoding>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                    </configuration>
                </plugin>
                <!-- Cucumber parallel plugin -->
                <plugin>
                    <groupId>com.github.temyers</groupId>
                    <artifactId>cucumber-jvm-parallel-plugin</artifactId>
                    <version>2.2.0</version>
                    <executions>
                        <execution>
                            <id>generateRunners</id>
                            <phase>validate</phase>
                            <goals>
                                <goal>generateRunners</goal>
                            </goals>
                            <configuration>
                                <glue>com.test.automation</glue>
                                <outputDirectory>${project.build.directory}/generated-test-sources/cucumber</outputDirectory>
                                <featuresDirectory>src/test/resources/features/</featuresDirectory>
                                <cucumberOutputDir>target/cucumber-reports</cucumberOutputDir>
                                <format>json</format>
                                <filterFeaturesByTags>true</filterFeaturesByTags>
                                <namingScheme>pattern</namingScheme>
                                <parallelScheme>SCENARIO</parallelScheme>
                                <namingPattern>{f}IT</namingPattern>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>   
        <dependencies>
            <!--Karate Dependencies  (This is creating a conflict) -->
                <dependency>
                    <groupId>com.intuit.karate</groupId>
                    <artifactId>karate-apache</artifactId>
                    <version>${karate.version}</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>com.intuit.karate</groupId>
                    <artifactId>karate-junit4</artifactId>
                    <version>${karate.version}</version>
                    <scope>test</scope>
                </dependency>
            <!--Karate Dependencies  (This is creating a conflict) -->
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-guice</artifactId>
                <version>${cucumber.version}</version>
            </dependency>
            <!-- test dependencies -->
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-java</artifactId>
                <version>${cucumber.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-junit</artifactId>
                <version>${cucumber.version}</version>
                <scope>test</scope>
            </dependency>
<!--Junit Dependeny  (This is creating a conflict with Karate) -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
                <scope>test</scope>
            </dependency>
<!--Junit Dependeny  (This is creating a conflict with Karate) -->      
        </dependencies>   
        <profiles>
            <profile>
                <id>serial</id>
                <activation>
                    <activeByDefault>true</activeByDefault>
                </activation>
                <properties>
                    <failsafe.fork.count>1</failsafe.fork.count>
                    <classes>**/AllTests.java</classes>
                </properties>
            </profile>
            <profile>
                <id>parallel</id>
                <properties>
                    <failsafe.fork.count>4</failsafe.fork.count>
                    <classes>**/*IT.java</classes>
                </properties>
            </profile>
        </profiles>
    </project>

Karate Runner File:

package com.test.automation.runner;

import com.intuit.karate.KarateOptions;
import com.intuit.karate.junit4.Karate;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;

@RunWith(Karate.class)
@KarateOptions(features = "classpath:tests_stories/Test.feature")
    public class KarateApiRunner {

    @BeforeClass
    public static void before() {
        System.setProperty("karate.config", "src/configs/karate-config.js");
    }
    }

Cucumber Runner File:

package com.test.automation.runner;    

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(
        glue = {"com.test.automation"},
        features = ".",
        plugin = {"pretty", "html:target/cucumber-report"},
        //  format = {"pretty", "json:target/cucumber-reports/cucumber.json"},
        tags = {"~@ignore","~@registration","@story"}
)
public class StoryRunner {
}

Stack Trace when I try to run the StoryRunner Class :

java.lang.NoSuchMethodError: cucumber.api.CucumberOptions.snippets()Lcucumber/api/SnippetType;

    at cucumber.runtime.RuntimeOptionsFactory.addSnippets(RuntimeOptionsFactory.java:61)
    at cucumber.runtime.RuntimeOptionsFactory.buildArgsFromOptions(RuntimeOptionsFactory.java:40)
    at cucumber.runtime.RuntimeOptionsFactory.create(RuntimeOptionsFactory.java:24)
    at cucumber.api.junit.Cucumber.<init>(Cucumber.java:56)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)


Process finished with exit code -1

The Karate Class works as expected. I have tried various things like removing Junit Dependencies and running Cucumbers tests with Karate.class but none works. Please suggest if there is something I am missing.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have a complex pom with many dependencies AND you are trying to add cucumber-jvm into the mix. Now it depends on which version of Karate you are using, see this: https://github.com/intuit/karate/issues/444#issuecomment-419852761

The best way for you to get ANY help on this is to follow this process, all the best: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...