1

@Peter I realize this is an old post, but I was wondering if you could possibly forward a working example of the karate-base and karate-config usage.

I am looking to setup a current project in a base root and service specific classpath structure, but would like to follow your recommended approach when implementing this base config.

The way I currently read the above and documentation is that it appears as though I would have to implement a config merge at the beginning of every feature run...is that correct?

Our base config would hold all environmental values based on the karate.env value while our service specific config would evaluate test data for that specific service as items like username, password, host header values, and other data items.

While I can output each config as a json object, the merge does not appear to work as detailed.

  Background: Authentication PreRequisites 
    * def DataSourceRow = 4
    * def configUpdate = call read('../../../service-config.js') {rowNum: '#(DataSourceRow)'}

resulting in

44:   karate.log('serviceConfig is:', var_serviceConfig);
45:   config = karate.merge(config, var_serviceConfig());
46:   karate.log('karate config is now:', config);
47: 
48:   return var_serviceConfig;
49: }
<<<<
org.graalvm.polyglot.PolyglotException: ReferenceError: "config" is not defined
- <js>.teamConfig(Unnamed:45)

Trying the same in a feature file results in an error as well

  Background: Authentication PreRequisites 
    * def DataSourceRow = 4
    * def configUpdate = callonce read('../../../service-config.js') {rowNum: '#(DataSourceRow)'}
    * print configUpdate
    * config = karate.merge(config, configUpdate())

resulting in

* config = karate.merge(config, configUpdate())
no step-definition method match found for: config = karate.merge(config, configUpdate())
mike
  • 383
  • 1
  • 12
  • I may get to this only later, but see if this answers your question: https://stackoverflow.com/a/58339662/143475 - this is standard Java / Maven technique. not sure if this helps but there is a unit-test that checks this: https://github.com/karatelabs/karate/blob/master/karate-core/src/test/java/com/intuit/karate/core/karate-config-frombase.feature - which is because of: https://github.com/karatelabs/karate/blob/master/karate-core/src/test/java/karate-base.js – Peter Thomas Feb 21 '23 at 18:37
  • Not looking to create separate jars, but more of a self merge of configs between classpaths Sample structure root - src/test/java - root files shared between all services with base config - api-test/java/net/companyname/servicename/tests with karate config to merge with base config - integration-test/java/net/companyname/servicename/tests with karate config to merge with base config – mike Feb 21 '23 at 18:53
  • er. then the answer you linked has the way I'd do it. read any JSON (or JS) from the classpath and manually merge. in `karate-config.js`. there are utils like `karate.merge()` that you can use (or plain JS). also make sure you see the option to use `karate.env` to auto-merge env specific files: https://github.com/karatelabs/karate#environment-specific-config - if you still need assistance, I insist on an example so you can explain what you are trying to do, I am lost – Peter Thomas Feb 21 '23 at 18:57
  • .. and re-reading your comment, karate may not be designed for such elaborate sharing. to be honest my gut reaction is this is over-engineering. FWIW no-one has ever asked for this before. I think your best bet is manually read files (from wherever or classpath) and DIY – Peter Thomas Feb 21 '23 at 18:59
  • In implementing the example given, as I understand it, I have our base config in the root class path **src/java/test**, and the service-config in the service's sub classpath **src/java/test/api-test/java/net/company/servicename**. Added results in original post – mike Feb 21 '23 at 20:28
  • classpath, use `classpath:some-file.js`. now I give up, please follow this process: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue – Peter Thomas Feb 22 '23 at 02:28
  • I uploaded a very simply example of trying to combine configs which do not work based on the comment from the initial post. https://github.com/Mike-c-Jackson/karate-base-config-use-sample – mike Feb 23 '23 at 04:02
  • that helps a lot ! can you take a look at this and let me know. https://github.com/Mike-c-Jackson/karate-base-config-use-sample/pull/1/files – Peter Thomas Feb 23 '23 at 05:00

0 Answers0