0

I'm new to cucumber. I have created a cucumber project but cannot seem to run the project. Every time I do, I get an error: java.lang.IllegalArgumentException: Not a file or directory: Here is how my project is set up:

|-src
  |-test
    |-java
      |-com
        |-project
          |-cucumber
              -Tester.java
              -MyFeature.feature
              -TestRunner.java

here's what is in Tester.java

public class Tester {

@Given("This is test one")
public void TestOne(){
    System.out.println("@Given -- This is test one");
}

@When("This is test two")
public void TeestTwo(){
    System.out.println("@When -- This is test two");
}

@Then("This is test three")
public void TestThree(){
    System.out.println("@Then -- This is test three");
}

@And("This is test four")
public void TestFour(){
    System.out.println("@And -- This is test four");
}

@But("This is test five")
public void TestFive(){
    System.out.println("@But -- This is test five");
}

}

And here's what is in tester.feature:

Feature: About Testers

  In order to get a high paid job
  As a Tester
  I want to learn Automation


Scenario: I am a Manual Tester
  Given This is test one
  When This is test two
  Then This is test three
  And This is test four
  But This is test five

And here's what is in testRunner.java:

@RunWith(Cucumber.class)
@CucumberOptions(
        format = {"pretty", "json:target/cucumber.json"},
        features = {"/src/test/java/com/project/cucumber"}
)
public class testRunner {}

This is the error i am getting:

java.lang.IllegalArgumentException: Not a file or directory: /src/test/java/com/project/cucumber/cucumber
    at cucumber.runtime.io.FileResourceIterator$FileIterator.<init>(FileResourceIterator.java:54)
    at cucumber.runtime.io.FileResourceIterator.<init>(FileResourceIterator.java:20)
    at cucumber.runtime.io.FileResourceIterable.iterator(FileResourceIterable.java:19)
    at cucumber.runtime.model.CucumberFeature.loadFromFeaturePath(CucumberFeature.java:101)
    at cucumber.runtime.model.CucumberFeature.load(CucumberFeature.java:54)
    at cucumber.runtime.model.CucumberFeature.load(CucumberFeature.java:34)
    at cucumber.runtime.RuntimeOptions.cucumberFeatures(RuntimeOptions.java:201)
    at cucumber.api.junit.Cucumber.<init>(Cucumber.java:60)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:101)
    at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:87)
    at com.intellij.junit4.JUnit46ClassesRequestBuilder.collectWrappedRunners(JUnit46ClassesRequestBuilder.java:90)
    at com.intellij.junit4.JUnit46ClassesRequestBuilder.getClassesRequest(JUnit46ClassesRequestBuilder.java:51)
    at com.intellij.junit4.JUnit4TestRunnerUtil.buildRequest(JUnit4TestRunnerUtil.java:91)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:39)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
  • When I run the test in a runner class test runs but when I tried running the test from the feature file I get this error " Not a file or directory: C:\Selenium\workspace\CucumberWork\src\ccumber\feature\search.feature" but when I move the the feature file to a package I could run the feature file, but could not run the runner class again. Move it around I could do again other way around anyways to solve this issue? – Ayodeji Feb 20 '17 at 16:36
  • Just create a new feature file , copy all the scenarios from the first feature file and paste it in the new one and delete the first one and try running again . – user25725 May 17 '17 at 4:36

10 Answers 10

1

Fixed the issue by removing '/' before the 'src'

  • you can mark yourself as solving your own problem - even though it is a trivial solution! – Marcus D May 17 '17 at 9:41
1
@CucumberOptions(features="Features",glue={"StepDefinition"})

For this issue, please give a full path of feature file location

@CucumberOptions(features="C:\\Users\\selenium pack\\cucu1",glue={"StepDefinition"})  
  • I don't know if it's a good idea to put absolute paths into that configuration... – nepa Apr 10 '18 at 11:48
1

This error clearly says that "Not a file or directory" which means the path is not correct. I assume that the feature files can be at the two places only:

  1. With in the src folder or src sub-folders.
  2. Outside the src folder, which means you keep your features files in some folder in the project but outside src package.

In the first case you should specify your CucumberOptions as below:

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "src/somefolder/Feature"

In the second case:

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "Feature")

Look at the example of second case here.

0

Here is the error you are getting:

java.lang.IllegalArgumentException: Not a file or directory: /src/test/java/com/project/cucumber/cucumber

Notice the file path:

/src/test/java/com/project/cucumber/cucumber

In your project directory, you list out the directories as follows:

/src/test/java/com/project/cucumber/

Therefore, there's one too many "cucumber" somewhere in your setup.

The only place I can see in the paste that references this path is this line: features = {"/src/test/java/com/project/cucumber"}.

Have you tried removing "cucumber" from that line? Perhaps the framework you're using is automatically adding "/cucumber" to your path.

  • I've done all possibilities with the path and still get the same error. – Saleh Qadan May 15 '15 at 17:18
  • @SalehQadan Then it's another directory path in an annotation somewhere else in your code. It's being thrown from the jUnit code, so you know it's an annotation, and it's clearly an incorrect path – Yamikuronue May 15 '15 at 17:20
  • I was able to fix the issue! something so simply as to taking out '/' at the beginning of 'src' – Saleh Qadan May 15 '15 at 17:46
0

This error occurs due to using older version of cucumber. This issue was solved in cucumber version 1.2.3

Make changes in your pom.xml

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

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-picocontainer</artifactId>
        <version>1.2.3</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.2.3</version>
        <scope>test</scope>
    </dependency>
0

Make sure your .feature file is on the same path as detailed in the error message. I move my .feature file to the path specified in the error message and it worked. It is definitely an issue with finding the correct path

0

** you didnt use in features line. you must use "/" in after cucumber **

    format = {"pretty", "json:target/cucumber.json"},

    features = {"/src/test/java/com/project/cucumber/"}
0

Move the Feature package with feature files under src/test/java which has your Test Runner files. This should resolve the issue.

0

I get the same error when running Cucumber tests with the JUnit runner from Android Studio. In my case it was because the IDE puts a wrong working directory in the run configuration. Example:

The error message was:

java.lang.IllegalArgumentException: Not a file or directory: /Users/me/project/app/app/src/test/resources/features

The directory should be /Users/me/project/app/src/test/resources/features, so one /app less.

Therefore in the run configuration I had to change the working directory from /Users/me/project/app to /Users/me/project, which made it work again.

0

Right Click on Feature File -> Run as -> Run Configurations

In the Feature Path you would be able to see path including

src/test/ .............

so just replace the link by using browse button availble in Feature Path

Browse for your project using that and identify the feature file and select the feature file.

Now see the differnce..

the new link to the feature will not be as length as it was before.

thats it, click apply

and now run..

you will be able to see what you were expecting.

Cheers !!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.