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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…