【问题标题】:Cucumber : java.lang.IllegalArgumentException: Not a file or directory: G:\Codebase\MavenCucumber\--plugin黄瓜:java.lang.IllegalArgumentException:不是文件或目录:G:\Codebase\MavenCucumber\--plugin
【发布时间】:2017-01-12 04:42:18
【问题描述】:

每当我尝试在 Eclipse 中运行我的功能文件时使用 Maven,我都会遇到以下错误:

线程“main”中的异常 java.lang.IllegalArgumentException:不是文件或目录:G:\Codebase\MavenCucumber--cucumber.runtime.io.FileResourceIterator$FileIterator.(FileResourceIterator.java:54) 处的插件.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) 在 cucumber.api.cli.Main.run(Main.java:20) 在 cucumber.api.runtime.Runtime.run(Runtime.java:92)。 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

【问题讨论】:

    标签: java maven cucumber-junit


    【解决方案1】:

    通过在项目下创建单独的文件夹(即“功能”)解决了该问题,而不是将功能文件保留在项目的子文件夹中。

    【讨论】:

      【解决方案2】:

      试试

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

      【讨论】:

        【解决方案3】:

        实际上,这个问题发生在我身上,因为功能文件名是用大写写的。当我将其更改为小写时,问题就解决了。

        【讨论】:

          【解决方案4】:

          以下 Cucumber Options 格式对我有用

          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"}
          }
          

          【讨论】:

            【解决方案5】:

            此错误清楚地表明“不是文件或目录”,这意味着路径不正确。这可能有多种原因。

            一个是将 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/

            【讨论】:

              【解决方案6】:

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

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

              【讨论】:

              • 谢谢。有一些问题,你的修复也对我有用。
              猜你喜欢
              • 2019-06-07
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2019-04-26
              • 1970-01-01
              • 2015-12-20
              • 2017-12-13
              相关资源
              最近更新 更多