json 文件和调用的功能在 jenkins 中找不到(使用空手道框架)

json files and called features not found in jenkins (with Karate Framework)


在我的功能中,我有: * def bar = read('classpath:features/xxx/foo.json')

但是当我在 Jenkins 中 运行 测试时,我有一个错误:

java.lang.RuntimeException: javascript evaluation failed: read('classpath:features/xxx/foo.json')
  at com.intuit.karate.Script.evalInNashorn(Script.java:423)
  at com.intuit.karate.Script.evalInNashorn(Script.java:394)
  at com.intuit.karate.Script.eval(Script.java:316)
  at com.intuit.karate.Script.eval(Script.java:194)
  at com.intuit.karate.Script.assign(Script.java:656)
  at com.intuit.karate.Script.assign(Script.java:587)
  at com.intuit.karate.StepDefs.def(StepDefs.java:265)
  at ✽.* def u = read('classpath:features/xxx/foo.json')(features/XXX/calling.feature:7)
Caused by: com.intuit.karate.exception.KarateFileNotFoundException: file not

found: features/xxx/foo.json, classpath: true at com.intuit.karate.FileUtils.readFileAsString(FileUtils.java:104) at com.intuit.karate.FileUtils.readFile(FileUtils.java:80) at jdk.nashorn.internal.scripts.Script$RecompilationA$\^eval_.L:1(:3) at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:639) at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494) at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393) at jdk.nashorn.api.scripting.ScriptObjectMirror.call(ScriptObjectMirror.java:117) at jdk.nashorn.internal.scripts.Script$\^eval_.:program(:1) at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:637) at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494) at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393) at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:449) at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:406) at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:402) at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155) at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264) at com.intuit.karate.Script.evalInNashorn(Script.java:419) at com.intuit.karate.Script.evalInNashorn(Script.java:394) at com.intuit.karate.Script.eval(Script.java:316) at com.intuit.karate.Script.eval(Script.java:194) at com.intuit.karate.Script.assign(Script.java:656) at com.intuit.karate.Script.assign(Script.java:587) at com.intuit.karate.StepDefs.def(StepDefs.java:265) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at cucumber.runtime.Utils.call(Utils.java:40) at cucumber.runtime.Timeout.timeout(Timeout.java:16) at cucumber.runtime.Utils.invoke(Utils.java:34) at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:38) at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37) at com.intuit.karate.cucumber.CucumberUtils.runStep(CucumberUtils.java:136) at com.intuit.karate.cucumber.KarateRuntime.runStep(KarateRuntime.java:78) at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44) at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39) at cucumber.runtime.model.CucumberScenario.runBackground(CucumberScenario.java:59) at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:42) at cucumber.runtime.model.CucumberScenarioOutline.run(CucumberScenarioOutline.java:46) at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165) at com.intuit.karate.cucumber.CucumberRunner.lambda$parallel[=13=](CucumberRunner.java:84) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)

`

怎么了?

如果我正确理解你的问题(它严重缺乏细节),那么在你的本地机器上一切正常,但在 Jenkins 上 运行 时不工作。

难道你没有更多的堆栈跟踪可以提供吗?

可能有很多可能的原因。也许在 Jenkins 上,非 Java 文件没有被正确复制到 target/test-classes。检查 Jenkins 上的 pom.xml 是否因为 Maven 配置文件而表现不同。您应该与您的 Jenkins 管理员/CI 团队合作解决这个问题。