Java: package cucumber.api.junit does not exist
Solution 1
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.
Solution 2
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
Solution 3
Change the imports.
instead of: import cucumber.api.junit.Cucumber;
use import io.cucumber.junit.Cucumber;
Chai
Updated on July 05, 2022Comments
-
Chai almost 2 years
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 CucumberThe 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!
-
Chai about 7 yearsThank 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 about 7 yearsEDIT: I made a comment but it doe'snt make sense... I found out... to be continued!
-
Chai about 7 yearsOk so: I downloaded it. Changed it to java8. When I saw it still worked renamed the project according to this answer. 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!
-
Thomas Sundberg about 7 yearsI'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: thinkcode.se/blog/2015/02/28/galls-law
-
Chai about 6 yearsThx. 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!
-
user3054986 almost 5 yearsYou could also consider putting the class importing "cucumber.api.junit" into the test folder. That was my problem using the TypeRegistryConfigurer: cucumber.io/docs/cucumber/configuration/#recommended-location