1

I have the following file karate-config-test.js

 function fn() {    
  var env = karate.env; // get system property 'karate.env'
  var baseUrl = "http://localhost:5000"
  var config = {
    env: env,
    baseUrl: baseUrl
  };

  //open connection to message broker (mqtt, amqp)
  var async_message = karate.callSingle('classpath:com/connect/apitests/commons/async_message/async_message.feature', config);
  config.mqtt = async_message.mqtt
  config.amqp = async_message.amqp
 
  return config;
}

And the following feature async_message.feature


@ignore

Feature: utility that instance async message broker
Background:
 
  * url baseUrl 

Scenario: Set instance of a class AmqpUtils And MqttUtils
    * def amqp = 'pippo'
   
Scenario: Set instance of a class MqttUtils
    * def mqtt = 'pluto'
 

when i check the value of the variable async_message i see the variables of one scenario but not both, for example I saw only mqtt. Why is this happening? In karate documentation I read

  • All variables that were defined (using def) in the 'called' script would be returned as 'keys' within a JSON-like object.
Rachid G
  • 190
  • 1
  • 7
  • sorry, this is too much to read and digest. also the use of `callSingle()` has effects that may be responsible. follow this process please: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue – Peter Thomas Jun 29 '23 at 15:44
  • @PeterThomas I update the desciption. my question is simple: when in the called feature have more than one scenario, the caller feature does not see all variables from the called feature – Rachid G Jun 29 '23 at 16:54
  • well yes, because it is designed to only call one scenario. the last scenario called is what you see in the return. you are welcome to submit a PR to improve the docs. – Peter Thomas Jun 29 '23 at 17:01

1 Answers1

1

Karate is designed so that when you do a call of any kind, the last Scenario is what is considered for returning variables.

In other words, the best practice is to call one Scenario at a time. You can use tags to "isolate" scenarios if you don't like splitting scenarios into different files.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248