Search code examples
testingbddkarate

Get Karate request data using another util service


One of the param for my API is security related and linked to the environment on which the test would run , essentially it will be dynamic. Since this is security related, I have an internal rest API that provides this data. I want to understand what is the effective way of getting this data in Karate feature?

I have tried two different ways: 1. Defined a java util and invoke the java type and def variable for holding the data

  1. Defined a Util method as part of karate-config.js

In karate-config.js

function getSomeData(someValue) {

    return Java.type('xyz.abc.util.MyUtil');
}

In the feature file defined a JS

* def dataFromJS = read('classpath:com/xyz/util/js_that_invokes_rest.js')

I want to understand if there is a pattern of how this should be done or if there is an explicit support in Karate for doing this?


Solution

  • I have an internal rest API

    Well. Did you just forget that Karate is all about making REST requests !? :)

    Please create a re-usable feature, make that REST call, define the variables that you need and now you can call it from other features.

    Please refer to the documentation: https://github.com/intuit/karate#calling-other-feature-files