How to use -a in command line?

浪尽此生 提交于 2020-01-04 14:04:20

问题


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 ?

My command line :

java -jar c:\karate\karate-0.9.1.jar -a myKey1=myValue1 TestArgs.feature

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 Feature: test args

Scenario: print args

* print myKey1
* print arg
* print karate.properties['myKey1']
* print karate.get('myKey1')

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 - Karate version: 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] INFO com.intuit.karate - karate.env system property was: null

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 - [print]

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 - [print]


回答1:


Actually we meant to delete the docs, apologies since the -a / --args option is not supported any more.

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

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

And this file karate-config-dev.js:

function() { return { myKey: 'hello' } }

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.



来源:https://stackoverflow.com/questions/54343563/how-to-use-a-in-command-line

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!