5

I am using Cucumber-JVM and Selenium WebDriver together. I have a Maven project in eclipse and dependency of pom.xml file is as below:

<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>1.2.2</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>1.2.2</version>
    <scope>test</scope>
</dependency>

The content of RunCukesTest.java file is:

import org.junit.runner.RunWith;
import cucumber.junit.Cucumber;
@RunWith(Cucumber.class)
@Cucumber.Options(format = {"pretty", "html:target/cucumber-htmlreport","json-pretty:target/cucumber-report.json"})
public class RunCukesTest {
}

I am getting the error in the following lines of code:

import cucumber.junit.Cucumber;
@RunWith(Cucumber.class)
@Cucumber.Options(format = {"pretty", "html:target/cucumber-htmlreport","json-pretty:target/cucumber-report.json"})

But when I used the version 1.0.14 it works well. What's the wrong with the latest version?

Raedwald
  • 46,613
  • 43
  • 151
  • 237
Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
  • what error message do you have? – Paizo Jul 08 '15 at 09:09
  • The import cucumber.junit cannot be resolved for "import cucumber.junit.Cucumber;" and Multiple markers at this line - Cucumber cannot be resolved to a type - Class cannot be resolved for next 2 lines of code – Ripon Al Wasim Jul 08 '15 at 09:23

7 Answers7

10

@Cucumber.Options is deprecated use @CucumberOptions instead

@CucumberOptions(
    format = "pretty",
    features = "//refer to Feature file"  
)

Hope this helps you

Vicky
  • 2,999
  • 2
  • 21
  • 36
5

The annotation has changed to @CucumberOptions:

And I think json-pretty has changed to json in this cucumber version.

This should work:

@CucumberOptions(
      format = {"pretty", "html:target/cucumber-htmlreport","json:target/cucumber-report.json"}
)

Moreover, according to cucumber-jvm specifications format is deprecated. You should replace by plugin. This also should work:

plugin = {"pretty", "html:target/cucumber-htmlreport","json:target/cucumber-report.json"}

Hope it helps

troig
  • 7,072
  • 4
  • 37
  • 63
3

with cucumber 1.2.2

<cucumber.version>1.2.2</cucumber.version>
....
    <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>
....

here a sample working test:

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(features = "classpath:features/myfeature.feature", tags = "@Mytag", plugin = {"pretty", "html:target/cucumber"})
public class MYAcceptanceTest {

}

note the import is cucumber.api.junit.Cucumber instead of cucumber.junit.Cucumber and you need to add the import for the cucumber options. The stereotype for the option is @CucumberOptions instead of @Cucumber.Options

Paizo
  • 3,986
  • 30
  • 45
2

replace @Cucumber.Options with @CucumberOptions and format with plugin

@CucumberOptions(plugin = {"pretty", "html:target/cucumber-htmlreport","json-pretty:target/cucumber-report.json"})
public class RunCukesTest {
}
Sankumarsingh
  • 9,889
  • 11
  • 50
  • 74
arunkumar sambu
  • 653
  • 1
  • 9
  • 22
1

You can try putting both RunCukesTest.java file and your Feature file in same folder or package.

suketup
  • 469
  • 7
  • 12
1

Cucumber version is now updated to version 2.0.1. Replace

<groupId>info.cukes</groupId>

with

<groupId>io.cucumber</groupId>
RRR
  • 75
  • 2
  • 11
0

By Adding Below Dependencies above issue got resolved

Please list of dependencies added in the POM

<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>FirstBBDApp</groupId>
    <artifactId>FirstBBDApp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>FirstBBDApp</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>1.2.5</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.5</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.5</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-core -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>1.2.5</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-jvm</artifactId>
            <version>1.2.5</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>net.masterthought</groupId>
            <artifactId>cucumber-reporting</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-jvm-deps</artifactId>
            <version>1.0.3</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-html -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-html</artifactId>
            <version>0.2.6</version>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.cobertura</groupId>
            <artifactId>cobertura</artifactId>
            <version>2.1.1</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>gherkin</artifactId>
            <version>2.12.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/info.cukes/gherkin-jvm-deps -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>gherkin-jvm-deps</artifactId>
            <version>1.0.3</version>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>2.0.2-beta</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.7.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/junit/junit-dep -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit-dep</artifactId>
            <version>4.11</version>
            <type>pom</type>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-chrome-driver</artifactId>
            <version>3.14.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.sun</groupId>
            <artifactId>tools</artifactId>
            <version>1.6</version>
            <scope>system</scope>
            <systemPath>C:\Program Files\Java\jdk1.8.0_202\lib\tools.jar</systemPath>
        </dependency>
    </dependencies>
</project>