karate.callSingle 在 karate-config.js 中找不到 .feature 文件

问题描述 投票:0回答:3

我正在使用空手道 v0.9.6,它是一个很棒的工具。 我有超过 1000 个场景,每个场景都需要令牌才能工作,因此我在 karate-config.js 中使用 callSingle 来创建和缓存令牌。我使用独立的 jar 文件。

我的 karate-config.js 的一部分:

  var auth_cfg = { 
  server: env,
  credentials: karate.properties['credentials']};

  var result = karate.callSingle('classpath:credentials/generate_tokens.feature', auth_cfg);

我正在使用这样的 .sh 文件:

rm -rf target &&
  java -Xmx2048m \
    -Dlogback.configurationFile=cfg/logs_debug.xml \
    -jar \
    -Dcredentials=data.json \
    karate-1.0.1.jar -e https://my-server/ \
    --tags ~fixme \
    --tags ~ignore \
    --threads 4 \
   features/services/simple_plan.feature

而且,它在 v.0.9.6 上运行很长时间都完美。 但是,当我尝试升级到 v 1.0 或 1.0.1 时,出现错误:

org.graalvm.polyglot.PolyglotException: not found: credentials/generate_tokens.feature

我发现了这个问题:https://github.com/intuit/karate/issues/1515

但是例子对我不起作用。我正在尝试使用“file:”和 karate.properties['karate.config.dir'] + '/features/auth/auth.feature'。 我总是遇到错误:

未找到:credentials/generate_tokens.feature

还有谁遇到过这个问题?

testing karate
3个回答
1
投票

正如您在 #1515 的讨论中看到的 - 这就是为什么我们真的希望更多的人尝试 RC 版本并向我们提供反馈(我们为此花费了几个月的时间)而不是等待 1.0。

您的情况似乎是一种边缘情况,您正在使用独立的 JAR 和自定义 shell 脚本。

我的第一个建议是使用

-w
标志。这是 1.0 中的一个新参数,可以设置“当前工作目录”,但在您的情况下它应该默认正确。

第二个建议是设置JVM的类路径。使用此作为参考:https://stackoverflow.com/a/58398958/143475 - 一旦你这样做,

classpath:
将按照你的预期工作。

否则请按照以下流程操作:https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue - 我不得不说,除非你能帮助我们解决这个问题,否则你可能会保持在 0.9.6 一段时间。对不起。


1
投票

Peter Thomas,感谢您的快速回复! 我修改 callSingle 函数和 callSingle 调用的 .feature 文件 - 将“classpath:”更改为“file:”

karate.callSingle('file:credentials/generate_tokens.feature', auth_cfg)

,

# read credentials
* def authdata = read('file:credentials/' + credentials)

现在可以使用了。之前,当我将 classpath: 更改为 file: i 时,可能犯了一个错误。 感谢如此出色的测试框架!


0
投票

感谢您的解决方案 当我用类路径替换文件时,它对我有用

© www.soinside.com 2019 - 2024. All rights reserved.