我正在尝试配置将在JBoss上部署的.war内部运行的Cucumber测试。此设置使用控制器启动黄瓜主管道。黄瓜需要用于粘合路径(-g)和特征文件路径的参数。通常,这些路径可能以classpath:开头,并且Cucumber正确标识了.feature文件(和步骤定义)(无论是在本地运行还是在已编译的.jar文件中)。但是,当编译为.war文件时,将引发以下异常:
java.nio.file.FileSystemNotFoundException: Provider "vfs" not installed
调试项目,Cucumber在这里寻找功能:
vfs:/C:/Users/{user}/EAP-7.1.0/bin/content/war-test-1.0-SNAPSHOT.war/WEB-INF/classes/features/
除了未安装'vfs'之外,/ bin /位置中没有/ content文件夹。查找如何加载资源位置应中的文件时,以下工作有效:
InputStream is = getClass().getClassLoader().getResourceAsStream("/features/Test.feature");
但是,当我通过/ features作为特征位置时,Cucumber会查找C:/ features。对于Cucumber如何决定加载其资源,我无能为力。是否有通过特征路径的正确方法,以便正确加载特征?
我准备了以下basic项目来重新创建问题:https://github.com/bgagnon93/cucumber-war
我正在本地Red Hat JBoss EAP 7.1服务器上运行Cucumber-war.war。在服务器上启动运行之后,可在localhost上访问webapp:http://localhost:8080/cucumber-war-1.0-SNAPSHOT/
单击“开始”按钮将启动黄瓜,并导致失败。
这是在PortalController类中黄瓜启动的样子:
@PostMapping("/")
public String run() {
String[] cucumberArgs = {
"-g", "classpath:com/automation/steps",
"--tags", "@Test",
"classpath:features"
};
Main.run(cucumberArgs, Thread.currentThread().getContextClassLoader());
return "test";
}
是否有通过特征路径的正确方法,以便正确加载特征?
您提供的是正确的路径。
黄瓜使用JSR203扫描特征文件。当前,Apaches VFS不支持JSR203。但是,vfs2nio可能会有些运气。