Maven-Cucumber项目抛出java.lang.IllegalArgumentException路径非法字符问题求助
解决Cucumber运行时的IllegalArgumentException错误
嘿,我一眼就揪出问题所在了——你碰到的这个java.lang.IllegalArgumentException: Illegal character in path at index 0: {StepDefinitions}错误,跟你折腾的features路径半毛钱关系都没有,问题出在TestRunner类里的glue属性配置上!
核心问题:Glue参数多了多余的大括号
你看你的@CucumberOptions里写的是glue= "{StepDefinitions}",这里的大括号{}完全是画蛇添足!Cucumber的glue参数只需要直接指定存放StepDefinitions的包名就行,不需要用大括号包裹。
把TestRunner改成下面这样就好:
package runner; import org.junit.runner.RunWith; import io.cucumber.junit.Cucumber; import io.cucumber.junit.CucumberOptions; @RunWith(Cucumber.class) @CucumberOptions( features="C:\\Users\\punia\\OneDrive\\Desktop\\Selenium Project All\\Eclipseworkspace\\CucumberFoodwatch\\src\\test\\resources\\features", glue= "StepDefinitions", // 去掉多余的大括号 plugin = {"json:target/cucumber.json"} ) public class TestRunner { }
顺便说下Features路径的小建议
你之前费劲把空格换成%20其实没必要,在Windows下Java字符串里直接写空格是能识别的,只要你用双反斜杠\\转义了路径里的单斜杠就没问题。要是怕绝对路径麻烦,还可以改成相对路径,比如:
features="src/test/resources/features"
这样不仅简洁,还能避免不同环境下的路径兼容问题。
依赖配置检查
另外看了你的pom.xml,cucumber-java和cucumber-junit版本都是6.11.0,版本匹配,maven-surefire插件和报告插件的配置也没什么问题,不用动。
改完glue的配置后重新跑TestRunner,这个IllegalArgumentException应该就消失啦!
内容的提问来源于stack exchange,提问作者sunil
相关产品推荐
相关产品推荐

