Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

213
Vistas
Karate environment value not getting set in config json

I have config-base.js which is loading the 'env_data.json' file. The java script in config-base.js is not setting the values in config as expected. I am trying to collect list of fields under common and appA parentElement and setting under config Json. This I could not achieve it.

I am passing appName as 'appA' and env as 'uat' via CLI command as like below java -cp karate:. -Dkarate.config.dir=. -Dkarate.appName=appA -jar karate.jar myFeature.feature -T 1 -t @smoke -e uat

I am trying to build config JSON as like below via JS.

config {
    baseUrl : 'http://uat.someurl.com'
    parameterX : 'x2',
    parameterY :'y2'
    someOtherBackendUrlA : 'http://uat.appA.com'
    parameterA : 'a2',
    parameterB :'b2'
}

My env_data.js is look like this

    [{
    appName : 'common',
    data: {
        uat: {
            baseUrl : 'http://uat.someurl.com'
            parameterX : 'x2',
            parameterY :'y2'
        }
    },{
    appName : 'appA',
    data: {
        uat: {
            someOtherBackendUrlA : 'http://uat.appA.com'
            parameterA : 'a2',
            parameterB :'b2'
        }
    }}]

My karate-base.js is written like below

function fn() {
  var env = karate.env;
  karate.log('karate.env system property was :', env);
  if (!env) {
    env = 'dev';
  }
  var listOfApplications = read('./env_data.json');
  var config = {};
  switch (env) {
    case "uat":
      for (var i = 0; i < listOfApplications.lenght; i++) {
        var appObject = listOfApplications[i];
        if (karate.properties['karate.appName'] == appObject.appName) {
          config = appObject.data[env];
        } else if ('common' == appObject.appName) {
          config.map(element => {
              element.baseUrl = appObject.data[env].baseUrl;
            }
          }
          break;
    }
karate.configure('connectTimeout', 5000);
karate.configure('readTimeout', 5000);
return config;
}

I can understand that, I am not mapping config values properly in else condition. I have tried map and foreach. but for these both functions, I got error saying org.graalvm.polyglotException:TypeError: config.map is not a funtion

I like to construct my config JSON along with common parameters on each application values. Please show some light on how can I fix this.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I have fixed the issue by below snippet.

fn();

function fn() {
  const env = 'uat';
  const userInput = 'appA';
  var listOfApplications = [
   {
      "appName":"common",
      "data":{
         "uat":{
            "baseUrl":"http://commonurl.com",
            "parameterX":"x",
            "parameterY":"y"
         }
      }
   },
   {
      "appName":"appA",
      "data":{
         "uat":{
            "baseUrl":"http://uat.appA.com",
            "parameterA":"a",
            "parameterB":"b"
         }
      }
   }
];
  
  var config={};
      for (var i = 0; i < listOfApplications.length; i++) {
          if (userInput == listOfApplications[i].appName) {
              config[userInput] = {...listOfApplications[i].data[env]};
          }else if ('common' == listOfApplications[i].appName) {
              config = {...listOfApplications[i].data[env]};
          }
      }
  
  //console.log(config);
  console.log(JSON.stringify(config));
  return config;
}

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda