Search code examples
karate

How to use karate.callSingle() in my karate-config.js?


The following is my karate-config.js file. The classpath for the feature that i want to call only once is classpath:com/test/scenario/accessToken.feature . where should i include the karate.callSingle()

function init() {
    karate.log('Env set to ', karate.env);
    karate.log('baseURL ', karate.properties['baseURL']);
    karate.log('OriginURl',karate.properties['OriginURL'])


    return {
        env: karate.env,

        SECRET: karate.properties['clientSecret'],
        TOKEN: {
            "CSRF": "",
            'ACCESS': ""
        },



        }
    };
}

Solution

  • You can include it anywhere, before you return the JSON. I suggest you take the help of someone who knows basic JavaScript near you, please. It is clearly mentioned in the documentation that this is for advanced users. If you have not understood my answer to your previous question, I have nothing more to add: https://stackoverflow.com/a/51288570/143475

    But let me try again. On line 13 you can do:

    var result = karate.callSingle('classpath:com/freshworks/freshid/test/scenario/accessToken.feature');
    

    And then on line 20 (this totally depends on how you have written accessToken.feature, I can't believe I am still trying to help you)

    TOKEN: {
      CSRF: result.csrf,
      ACCESS: result.access
    }