如何在命令行中使用-a? [英] How to use -a in command line?
问题描述
正如为独立jar所记录的那样,我试图为我的功能提供args,但无法弄清楚如何使其工作.我想念什么?
As documented for standalone-jar I'm trying to provide args to my feature and can't figure how to get it work. what do I miss ?
我的命令行:
java -jar c:\karate\karate-0.9.1.jar -a myKey1=myValue1 TestArgs.feature
karate-config.js
karate-config.js
function fn() {
var env = karate.env;
karate.log('karate.env system property was:', env);
if (!env) {
env = 'test';
}
var config = { // base config JSON
arg:karate.properties['myKey1']
};
return config;
}
TestArgs.feature 功能:测试参数
TestArgs.feature Feature: test args
Scenario: print args
* print myKey1
* print arg
* print karate.properties['myKey1']
* print karate.get('myKey1')
我什么都没打印: java -jar c:\ karate \ karate-0.9.1.jar -a myKey1 = myValue1 TestArgs.feature
I don't get anything printed : java -jar c:\karate\karate-0.9.1.jar -a myKey1=myValue1 TestArgs.feature
10:32:57.904 [main] INFO com.intuit.karate.netty.Main-空手道版本:0.9.1
10:32:57.904 [main] INFO com.intuit.karate.netty.Main - Karate version: 0.9.1
10:32:58.012 [main] INFO com.intuit.karate.Runner-空手道版本:0.9.1
10:32:58.012 [main] INFO com.intuit.karate.Runner - Karate version: 0.9.1
10:32:58.470 [ForkJoinPool-1-worker-1]信息com.intuit.karate-karate.env系统属性为:空
10:32:58.470 [ForkJoinPool-1-worker-1] INFO com.intuit.karate - karate.env system property was: null
10:32:58.489 [ForkJoinPool-1-worker-1] INFO com.intuit.karate-[打印]
10:32:58.489 [ForkJoinPool-1-worker-1] INFO com.intuit.karate - [print]
10:32:58.491 [ForkJoinPool-1-worker-1] INFO com.intuit.karate-[打印]
10:32:58.491 [ForkJoinPool-1-worker-1] INFO com.intuit.karate - [print]
10:32:58.495 [ForkJoinPool-1-worker-1]信息com.intuit.karate-[打印]
10:32:58.495 [ForkJoinPool-1-worker-1] INFO com.intuit.karate - [print]
10:32:58.501 [ForkJoinPool-1-worker-1] INFO com.intuit.karate-[打印]
10:32:58.501 [ForkJoinPool-1-worker-1] INFO com.intuit.karate - [print]
推荐答案
实际上,我们打算删除文档,很抱歉,因为不再支持-a / --args
选项.
Actually we meant to delete the docs, apologies since the -a / --args
option is not supported any more.
您当然可以使用karate.properties['some.key']
方法从命令行解包值.另请参阅如何获取环境变量: https://github.com/intuit/karate/Issues/547
You can of course use the karate.properties['some.key']
approach to unpack values from the command-line. Also refer how you can even get environment variables: https://github.com/intuit/karate/issues/547
我的建议是,如果需要,您可以使用karate-config-<env>.js
从文件中读取一堆变量.例如,鉴于此功能:
My suggestion is you can use karate-config-<env>.js
to read a bunch of variables from a file if needed. For example, given this feature:
Feature:
Scenario:
* print myKey
这个文件karate-config-dev.js
:
function() { return { myKey: 'hello' } }
您可以运行以下命令,该命令将自动加载config js文件:
You can run this command, which will auto load the config js file:
java -jar karate.jar -e dev test.feature
我们将更新文档.感谢您抓住这一点.
We will update the docs. Thanks for catching this.
这篇关于如何在命令行中使用-a?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!