当我以响应方式运行MainRunner类时,在控制台中出现如下错误消息。我确实设置了文件夹权限。
这是我的阶梯课:
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 stackoverflow webstie$")
public void user_navigate_to_stackoverflow_webstie() throws Throwable {
System.out.println("user_navigate_to_stackoverflow_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 stackoverflow webstie(\\d+)$")
public void user_navigate_to_stackoverflow_webstie2(int arg1) throws Throwable {
System.out.println("user_navigate_to_stackoverflow_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专业版上。我也尝试在管理员模式下运行Eclipse,但这也没有帮助。
这是我的Pom.xml https://pastebin.com/ad2qyGRH
我也尝试了以下方法:
运行:Eclipse菜单“项目”>“清理...”
但是没有喜悦。有谁知道是什么原因造成的?
亲切的问候
答案 0 :(得分:0)
当具有输出目录名称(cucumber.runtime.CucumberException: java.io.IOException: Failed to create directory ...
)的文件已经存在时,发生target/cucumber
异常。
假设以下结构
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使用的是黄瓜版本2.0.0-SNAPSHOT
。因为方法reportFileOutputStream
在类HTMLFormatter
中被重命名为createReportFileOutputStream
(SHA1:486b82cb9)。在发布黄瓜版本2.0.0
之前。
编辑:一些更详细的说明。主要问题是插件尝试创建具有相同名称target/cucumber
的目录条目。
target/cucumber
target/cucumber
如上所述,当应该创建目录并且已经存在相同目录的文件时,抛出异常Failed to create directory
。
可以在CucumberOptions
中紧随TestRunner.java
之后复制它。
@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"
)的输出文件名将解决此问题。
答案 1 :(得分:0)
从我发现的情况来看,plugin
对象似乎正在尝试创建2个称为“黄瓜”的目录,而您想要的是该对象创建目录和文件叫做黄瓜。这就是您的对象的样子:
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
别忘了删除空白! 然后,该空白将创建一个名为“目标”的单独文件夹(以空格开头),并将report.html文件放在其中,而不是其余的报告工件。
希望这会有所帮助!