1
votes

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

2
Move the CucumberFeaturesFolder inside src\test\resources. The 'features' option will become "src/test/resources/CucumberFeaturesFolder/CucumberFeatureFile.feature". The 'glue' option is defined in terms of java package - "CucumberTestDefinition". Upgrade junit and cucumber to the latest. Give it a shot... - Grasshopper
@Grasshopper Thanks for the reply. I tried out your suggestion. I got the following error: Exception in thread "main" java.lang.IllegalArgumentException: Not a file or directory: /Users/Saket/Documents/workspace/com.learnautomation.cucumber/CucumberFeaturesFolder/CucumberFeatureFile.feature - Saket Sinha
@Grasshopper I also tried upgrading cucumber and junit to 1.2.5, didn't help. - Saket Sinha

2 Answers

2
votes

Change

glue = {"src/test.java/CucumberTestDefinition"}

to

glue = {"src/test/java/CucumberTestDefinition"}

1
votes

Make sure the Java version is compatible with cucumber dependencies and other dependencies added in POM.xml. Earlier I was tried with JDK 7 but after changing to JDK 8, the error/exception was no longer visible at runtime and was able to execute the test successfully.