黄瓜异常创建目录失败
Cucumber Exception Failed to create directory
当我 运行 MainRunner class 作为响应时,我在控制台中收到如下错误消息。我确实为文件夹设置了权限。
这是我的步骤class:
package CucumberFramework.steps;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class LoginSteps {
@Given("^User navigate to Whosebug webstie$")
public void user_navigate_to_Whosebug_webstie() throws Throwable {
System.out.println("user_navigate_to_Whosebug_webstie");
}
@Given("^User clicks on the login button$")
public void user_clicks_on_the_login_button() throws Throwable {
System.out.println("user_clicks_on_the_login_button");
}
@Given("^User enters valid username$")
public void user_enters_valid_username() throws Throwable {
System.out.println("user_enters_valid_username");
}
@Given("^User enters valid password$")
public void user_enters_valid_password() throws Throwable {
System.out.println("user_enters_valid_password");
}
@When("^User clicks again on the login button$")
public void user_clicks_again_on_the_login_button() throws Throwable {
System.out.println("user_clicks_again_on_the_login_button");
}
@Then("^User should be taken to the sucsfull login page$")
public void user_should_be_taken_to_the_sucsfull_login_page() throws Throwable {
System.out.println("user_should_be_taken_to_the_sucsfull_login_page");
}
@Given("^User navigate to Whosebug webstie(\d+)$")
public void user_navigate_to_Whosebug_webstie2(int arg1) throws Throwable {
System.out.println("user_navigate_to_Whosebug_webstie2");
}
@Given("^User clicks on the login button(\d+)$")
public void user_clicks_on_the_login_button2(int arg1) throws Throwable {
System.out.println("user_clicks_on_the_login_button2");
}
@Given("^User enters valid username(\d+)$")
public void user_enters_valid_username2(int arg1) throws Throwable {
System.out.println("user_enters_valid_username2");
}
@Given("^User enters valid password(\d+)$")
public void user_enters_valid_password2(int arg1) throws Throwable {
System.out.println("user_enters_valid_password2");
}
@When("^User clicks again on the login button(\d+)$")
public void user_clicks_again_on_the_login_button2(int arg1) throws Throwable {
System.out.println("user_clicks_again_on_the_login_button2");
}
@Then("^User should be taken to the sucsfull login page(\d+)$")
public void user_should_be_taken_to_the_sucsfull_login_page2(int arg1) throws Throwable {
System.out.println("user_should_be_taken_to_the_sucsfull_login_page2");
}
}
我还查看了目标文件夹的权限,并确保为所有用户授予了权限。我正在使用 Windows 10 Pro。我也尝试 运行 Eclipse 在管理员模式下也没有帮助。
这是我的Pom.xml
https://pastebin.com/ad2qyGRH
我也试过以下方法:
运行ning: Eclipse 菜单项目 > 清理...
但没有快乐。请问有人知道是什么原因造成的吗?
亲切的问候
当名为输出目录 (target/cucumber
) 的文件已经存在时,会发生异常 cucumber.runtime.CucumberException: java.io.IOException: Failed to create directory ...
。
假设结构如下
src/test/java/runner/TestRunner.java
pom.xml
pom.xml 依赖关系
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.cucumber>2.0.0</version.cucumber>
</properties>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${version.cucumber}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${version.cucumber}</version>
<scope>test</scope>
</dependency>
</dependencies>
TestRunner.java
package runner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(plugin = { "html:target/cucumber" })
public class TestRunner {
}
重现步骤
$ mvn clean test-compile
$ echo "some text" > target/cucumber
现在文件target/cucumber
存在,运行测试
$ mvn test
它失败了
Caused by: cucumber.runtime.CucumberException: java.io.IOException: Failed to create directory /tmp/cuke.test/target/cucumber
at cucumber.runtime.formatter.HTMLFormatter.createReportFileOutputStream(HTMLFormatter.java:520)
at cucumber.runtime.formatter.HTMLFormatter.createJsOut(HTMLFormatter.java:510)
at cucumber.runtime.formatter.HTMLFormatter.<init>(HTMLFormatter.java:123)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
基于上述堆栈跟踪和 OP 屏幕截图中的行号。 OP 似乎使用了 Cucumber 版本 2.0.0-SNAPSHOT
。因为方法 reportFileOutputStream
在 class HTMLFormatter
中被重命名为 createReportFileOutputStream
(SHA1: 486b82cb9)。这是在 Cucumber 版本 2.0.0
发布之前。
编辑: 一些更详细的解释。主要问题是插件试图创建一个同名的目录条目 target/cucumber
.
- html - 将创建一个 目录
target/cucumber
- json - 将创建一个 文件
target/cucumber
如上所述,异常 Failed to create directory
被抛出,当一个目录应该被创建并且一个相同的文件已经存在时。
可以在TestRunner.java
.
中使用以下CucumberOptions
转载
@CucumberOptions(plugin = {"json:target/cucumber", "html:target/cucumber"})
cucumber.runtime.CucumberException: cucumber.runtime.CucumberException: \
java.io.IOException: Failed to create directory /.../target/cucumber
注意: 在 OP 的代码中,插件的顺序不是 json - html
,而是 html - json
。因此,上面的代码片段仅使用了 html
插件并在 运行 测试之前创建了文件 target/cucumber
。
按照 OP 屏幕截图中显示的相同顺序使用插件会引发不同的异常。
@CucumberOptions(plugin = {"html:target/cucumber", "json:target/cucumber"})
cucumber.runtime.CucumberException: java.io.FileNotFoundException: \
target/cucumber (Is a directory)
根据用于重现冲突的步骤,插件顺序与屏幕截图中的异常不匹配。
很可能更改 json 插件 ("json:target/cucumber.json"
) 的输出文件名将解决问题。
根据我的发现,plugin
对象似乎正在尝试创建 2 个名为 "cucumber" 的目录,而您想要的是让对象创建 目录和一个名为 cucumber 的文件。这是您的对象的样子:
plugin = {
"pretty",
"html:target/cucumber", //this is telling cucumber to create a folder called cucumber
"json:target/cucumber", //this is also telling cucumber to create a folder called cucumber
//even though you just need a file called cucumber.json
"com.cucumber.listener.ExtentCucumberFormatter: target/report.html"
//there is an unnecessary white space before "target" that is causing another issue
}
您要做的是:
plugin = {
"pretty",
"html:target/cucumber", //create a folder called cucumber
"json:target/cucumber.json",
//Notice the corresponding file extension (.json) telling cucumber to create a file
"com.cucumber.listener.ExtentCucumberFormatter:target/report.html"
//Notice I remove the white space at :target/report.html
}
现在代码正在创建一个名为 cucumber 的文件夹(这将包含一个显示测试结果的基本网页)和一个文件称为 cucumber.json(这将是相同的测试结果,但采用 json 格式)
别忘了去掉那个白色的space!
那个白色 space 然后创建一个名为“target”的单独文件夹(以空白 space 开头)并将 report.html 文件放在那里,而不是与其余的报告工件一起放在那里。
希望对您有所帮助!
这通常发生在插件写入冲突路径时。
例如:json:target/cucumber/report.json, html:target/cucumber
.
要解决此问题,请确保路径不发生冲突或碰撞。
例如:json:target/cucumber/report.json, html:target/cucumber/report.html
。请注意 report.json
和 report.html
都是文件(带有扩展名)。如果你至少将其中一个设为目录(不带扩展名),运行时会抛出异常。
当我 运行 MainRunner class 作为响应时,我在控制台中收到如下错误消息。我确实为文件夹设置了权限。
这是我的步骤class:
package CucumberFramework.steps;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class LoginSteps {
@Given("^User navigate to Whosebug webstie$")
public void user_navigate_to_Whosebug_webstie() throws Throwable {
System.out.println("user_navigate_to_Whosebug_webstie");
}
@Given("^User clicks on the login button$")
public void user_clicks_on_the_login_button() throws Throwable {
System.out.println("user_clicks_on_the_login_button");
}
@Given("^User enters valid username$")
public void user_enters_valid_username() throws Throwable {
System.out.println("user_enters_valid_username");
}
@Given("^User enters valid password$")
public void user_enters_valid_password() throws Throwable {
System.out.println("user_enters_valid_password");
}
@When("^User clicks again on the login button$")
public void user_clicks_again_on_the_login_button() throws Throwable {
System.out.println("user_clicks_again_on_the_login_button");
}
@Then("^User should be taken to the sucsfull login page$")
public void user_should_be_taken_to_the_sucsfull_login_page() throws Throwable {
System.out.println("user_should_be_taken_to_the_sucsfull_login_page");
}
@Given("^User navigate to Whosebug webstie(\d+)$")
public void user_navigate_to_Whosebug_webstie2(int arg1) throws Throwable {
System.out.println("user_navigate_to_Whosebug_webstie2");
}
@Given("^User clicks on the login button(\d+)$")
public void user_clicks_on_the_login_button2(int arg1) throws Throwable {
System.out.println("user_clicks_on_the_login_button2");
}
@Given("^User enters valid username(\d+)$")
public void user_enters_valid_username2(int arg1) throws Throwable {
System.out.println("user_enters_valid_username2");
}
@Given("^User enters valid password(\d+)$")
public void user_enters_valid_password2(int arg1) throws Throwable {
System.out.println("user_enters_valid_password2");
}
@When("^User clicks again on the login button(\d+)$")
public void user_clicks_again_on_the_login_button2(int arg1) throws Throwable {
System.out.println("user_clicks_again_on_the_login_button2");
}
@Then("^User should be taken to the sucsfull login page(\d+)$")
public void user_should_be_taken_to_the_sucsfull_login_page2(int arg1) throws Throwable {
System.out.println("user_should_be_taken_to_the_sucsfull_login_page2");
}
}
我还查看了目标文件夹的权限,并确保为所有用户授予了权限。我正在使用 Windows 10 Pro。我也尝试 运行 Eclipse 在管理员模式下也没有帮助。
这是我的Pom.xml https://pastebin.com/ad2qyGRH
我也试过以下方法:
运行ning: Eclipse 菜单项目 > 清理...
但没有快乐。请问有人知道是什么原因造成的吗?
亲切的问候
当名为输出目录 (target/cucumber
) 的文件已经存在时,会发生异常 cucumber.runtime.CucumberException: java.io.IOException: Failed to create directory ...
。
假设结构如下
src/test/java/runner/TestRunner.java
pom.xml
pom.xml 依赖关系
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.cucumber>2.0.0</version.cucumber>
</properties>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${version.cucumber}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${version.cucumber}</version>
<scope>test</scope>
</dependency>
</dependencies>
TestRunner.java
package runner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(plugin = { "html:target/cucumber" })
public class TestRunner {
}
重现步骤
$ mvn clean test-compile
$ echo "some text" > target/cucumber
现在文件target/cucumber
存在,运行测试
$ mvn test
它失败了
Caused by: cucumber.runtime.CucumberException: java.io.IOException: Failed to create directory /tmp/cuke.test/target/cucumber
at cucumber.runtime.formatter.HTMLFormatter.createReportFileOutputStream(HTMLFormatter.java:520)
at cucumber.runtime.formatter.HTMLFormatter.createJsOut(HTMLFormatter.java:510)
at cucumber.runtime.formatter.HTMLFormatter.<init>(HTMLFormatter.java:123)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
基于上述堆栈跟踪和 OP 屏幕截图中的行号。 OP 似乎使用了 Cucumber 版本 2.0.0-SNAPSHOT
。因为方法 reportFileOutputStream
在 class HTMLFormatter
中被重命名为 createReportFileOutputStream
(SHA1: 486b82cb9)。这是在 Cucumber 版本 2.0.0
发布之前。
编辑: 一些更详细的解释。主要问题是插件试图创建一个同名的目录条目 target/cucumber
.
- html - 将创建一个 目录
target/cucumber
- json - 将创建一个 文件
target/cucumber
如上所述,异常 Failed to create directory
被抛出,当一个目录应该被创建并且一个相同的文件已经存在时。
可以在TestRunner.java
.
CucumberOptions
转载
@CucumberOptions(plugin = {"json:target/cucumber", "html:target/cucumber"})
cucumber.runtime.CucumberException: cucumber.runtime.CucumberException: \
java.io.IOException: Failed to create directory /.../target/cucumber
注意: 在 OP 的代码中,插件的顺序不是 json - html
,而是 html - json
。因此,上面的代码片段仅使用了 html
插件并在 运行 测试之前创建了文件 target/cucumber
。
按照 OP 屏幕截图中显示的相同顺序使用插件会引发不同的异常。
@CucumberOptions(plugin = {"html:target/cucumber", "json:target/cucumber"})
cucumber.runtime.CucumberException: java.io.FileNotFoundException: \
target/cucumber (Is a directory)
根据用于重现冲突的步骤,插件顺序与屏幕截图中的异常不匹配。
很可能更改 json 插件 ("json:target/cucumber.json"
) 的输出文件名将解决问题。
根据我的发现,plugin
对象似乎正在尝试创建 2 个名为 "cucumber" 的目录,而您想要的是让对象创建 目录和一个名为 cucumber 的文件。这是您的对象的样子:
plugin = {
"pretty",
"html:target/cucumber", //this is telling cucumber to create a folder called cucumber
"json:target/cucumber", //this is also telling cucumber to create a folder called cucumber
//even though you just need a file called cucumber.json
"com.cucumber.listener.ExtentCucumberFormatter: target/report.html"
//there is an unnecessary white space before "target" that is causing another issue
}
您要做的是:
plugin = {
"pretty",
"html:target/cucumber", //create a folder called cucumber
"json:target/cucumber.json",
//Notice the corresponding file extension (.json) telling cucumber to create a file
"com.cucumber.listener.ExtentCucumberFormatter:target/report.html"
//Notice I remove the white space at :target/report.html
}
现在代码正在创建一个名为 cucumber 的文件夹(这将包含一个显示测试结果的基本网页)和一个文件称为 cucumber.json(这将是相同的测试结果,但采用 json 格式)
别忘了去掉那个白色的space! 那个白色 space 然后创建一个名为“target”的单独文件夹(以空白 space 开头)并将 report.html 文件放在那里,而不是与其余的报告工件一起放在那里。
希望对您有所帮助!
这通常发生在插件写入冲突路径时。
例如:json:target/cucumber/report.json, html:target/cucumber
.
要解决此问题,请确保路径不发生冲突或碰撞。
例如:json:target/cucumber/report.json, html:target/cucumber/report.html
。请注意 report.json
和 report.html
都是文件(带有扩展名)。如果你至少将其中一个设为目录(不带扩展名),运行时会抛出异常。