I have gone through all previous StackOverflow issues related to the same. This post will be long so please bear with me. The folders in my cucumber project are ordered as follows:
-src/main/java
-src/main/resources
-src/test/java
-|CucumberRunner (package)
-|CucumberTestRunner.java
-|CucumberTestDefinition (package)
-|CucumberStepDefinition.java
-src/test/resources
-CucumberFeaturesFolder
-|CucumberFeatureFile.feature
Here is a picture of the arrangement of the Project folders if the above order did not make sense to you. Order of project folders inside the project
My pom.xml has the following dependency added (no more dependency):
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.2</version>
<scope>test</scope>
</dependency>
My CucumberTestRunner.java file contains the following:
package CucumberRunner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(
features = "CucumberFeaturesFolder/CucumberFeatureFile.feature",
glue = {"src/test.java/CucumberTestDefinition"}
)
public class CucumberTestRunner {}
The error that I get when I try to run CucumberFeatureFile.feature is the following:
cucumber.runtime.CucumberException: Failed to instantiate class CucumberTestDefinition.CucumberStepDefinition
Now, after reading the similar posts mentioned on StackOverflow, I tried changing the version of cucumber-unit & cucumber-java from 1.2.2 to 1.2.0 which also resulted in an error but a different one:
Exception in thread “main” cucumber.runtime.CucumberException: No backends were found