黄瓜:java.lang.IllegalArgumentException:不是文件或目录:G:\Codebase\MavenCucumber\--plugin

Cucumber : java.lang.IllegalArgumentException: Not a file or directory: G:\Codebase\MavenCucumber\--plugin

每当我尝试使用 Maven 运行 我在 eclipse 中的功能文件时出现以下错误:

Exception in thread "main" java.lang.IllegalArgumentException: Not a file or directory: G:\Codebase\MavenCucumber--plugin at cucumber.runtime.io.FileResourceIterator$FileIterator.(FileResourceIterator.java:54) at cucumber.runtime.io.FileResourceIterator.(FileResourceIterator.java:20) at cucumber.runtime.io.FileResourceIterable.iterator(FileResourceIterable.java:19) at cucumber.runtime.model.CucumberFeature.load(CucumberFeature.java:38) at cucumber.runtime.RuntimeOptions.cucumberFeatures(RuntimeOptions.java:117) at cucumber.runtime.Runtime.run(Runtime.java:92) at cucumber.api.cli.Main.run(Main.java:20) at cucumber.api.cli.Main.main(Main.java:12)

上图是我的项目结构,功能文件包含以下代码-

@tag
Feature: Proof of Concept

  @tag1
  Scenario: This is my first test Scenerio
    Given This is my first step
    When This is my second step
    Then This is my third step

我正在为 cucumber-java、cucumber-junit、cucumber-picocontainer 使用 1.1.2 版本的 jar。因此,我遇到了上述错误。

现在我使用的是 1.2.2 版本的 jar,它在这个版本上工作得非常好。

这个错误明明是"Not a file or directory",意思是路径不正确。这可能有多种原因。

一个是将 Cucumple 库升级到最新版本,这对你的情况有效。

其次是功能文件的放置。我假设功能文件只能在两个地方:

  1. 在 src 文件夹或 src 子文件夹中。
  2. 在 src 文件夹之外,这意味着您将功能文件保存在项目中的某个文件夹中,但在 src 包之外。

在第一种情况下,您应该按如下方式指定 CucumberOptions:

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

第二种情况:

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

这里看第二种情况的例子http://toolsqa.com/cucumber/first-cucumber-selenium-java-test/

下面的黄瓜选项格式对我有用

src\main\java\com.qa.features
com.qa.stepDefinition

@RunWith(Cucumber.class)
@CucumberOptions(
    features = "src\main\java\com\qa\features"
    ,glue={"com/qa/stepDefinition"}
    ,format={"pretty","html:test-output"}
}

其实,这个问题发生在我身上,因为特征文件名是大写的。当我把它改成小写时,问题就解决了。

尝试

mvn test -Dcucumber.options="--tags @TagName"

问题已通过在项目下创建一个单独的文件夹即 'Feature' 解决,而不是将功能文件保存在项目的子文件夹中。