4

I've been trying to get this to work.

I would like set up a test runner class like so

However I get this error:

Error:(3, 26) java: package cucumber.api.junit does not exist
Error:(10, 10) java: cannot find symbol
symbol: class Cucumber

The class looks like:

package nl.prvgld.sigma.aanvraagtitels.testutil;

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

@RunWith(Cucumber.class)
public class RunFeature {
}

Pom.xml looks like:

<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/maven-v4_0_0.xsd">
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
  <modelVersion>4.0.0</modelVersion>
  <groupId>nl.prvgld.sigma.aanvraagtitels</groupId>
  <artifactId>Aanvraagtitels</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Aanvraagtitels</name>
  <url>http://maven.apache.org</url>
  <dependencies>
      <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
      <dependency>
          <groupId>org.seleniumhq.selenium</groupId>
          <artifactId>selenium-java</artifactId>
          <version>3.2.0</version>
      </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java8</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>
          <scope>test</scope>
      </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/com.microsoft.sqlserver/mssql-jdbc -->
      <dependency>
          <groupId>com.microsoft.sqlserver</groupId>
          <artifactId>mssql-jdbc</artifactId>
          <version>6.1.0.jre8</version>
      </dependency>
      <dependency>
          <groupId>com.smartbear.readyapi.testserver.cucumber</groupId>
          <artifactId>testserver-cucumber-core</artifactId>
          <version>1.0.0</version>
          <scope>test</scope>
      </dependency>


  </dependencies>
</project>

All classes are somewhere under the Test folder. I've been lookin at some related questions here and tried the solutions like removing test from Pom, and making sure I have junit, cucumber-junit, cucumber-java8 and cucumber-core in the Pom.

I am using Intellij.

Any help in the right direction is highly appreciated!

Cheers!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Chai
  • 1,796
  • 2
  • 18
  • 31

3 Answers3

7

I don't know if you already resolved your issue but you can quickly fix it by removing the scope tags from your pom.xml file. Do this action for all dependencies that you are facing issues and should work fine.

Cheers, HH

Higor Haider
  • 71
  • 1
  • 3
  • Thx. This has been resolved with the solution above. I remember trying your idea but that did not work in that case. Somehow that project was broken. But anyway, it has been resolved. Thx for the effort of answering though! – Chai Mar 11 '18 at 10:37
  • You could also consider putting the class importing "cucumber.api.junit" into the test folder. That was my problem using the TypeRegistryConfigurer: https://cucumber.io/docs/cucumber/configuration/#recommended-location – user3054986 May 24 '19 at 13:07
5

By inspection, everything looks good. But obviously, it doesn't work as you expect.

Do you get the same error when compiling with IDEA and compiling with Maven?

To get started, I would clone a getting started project from the Cucumber team and get it working. It is much easier to later extend it to contain the things you need. Clone https://github.com/cucumber/cucumber-java-skeleton and build it using Maven with

mvn clean install

It is expected to work out of the box.

With a working solution, take small steps toward the project you actually would like to have.

Thomas Sundberg
  • 4,098
  • 3
  • 18
  • 25
  • Thank you Thomas. I already have about 20 classes (modelling the UI and some helper stuff), so doing what you suggest might be the best idea but it will take work. I was hoping for a quicker solution. I'll first try compiling with maven. I haven't done that. Is it that same mvn clean install? – Chai Mar 22 '17 at 07:58
  • EDIT: I made a comment but it doe'snt make sense... I found out... to be continued! – Chai Mar 22 '17 at 13:08
  • Ok so: I downloaded it. Changed it to java8. When I saw it still worked renamed the project according to [this answer](http://stackoverflow.com/a/36509634/6583529). Then i put all the packages and classes in their place and it works like a charm! Somehow also the colouring is different, so I suspect something was off with the initial setup of my project. Anyway, thanks a lot! – Chai Mar 22 '17 at 14:12
  • 2
    I'm very glad to hear that it worked out for you. I think you had a case of Gall's law. More about it here: http://www.thinkcode.se/blog/2015/02/28/galls-law – Thomas Sundberg Mar 25 '17 at 11:29
1

Change the imports.

instead of: import cucumber.api.junit.Cucumber;

use import io.cucumber.junit.Cucumber;

Pirate
  • 1,167
  • 1
  • 9
  • 19