How to see the values of "configure" settings in Karate?

55 Views Asked by At

In Karate, you can set certain framework settings via the configure keyword, such as

* configure httpTimeout = 5000

* configure ssl = true

* eval karate.configure('readTimeout',10000);

But how can you see the values of these settings? Can you determine the defaults? What if you need to temporarily override them for part of a test and restore the previous value afterwards?

1

There are 1 best solutions below

1
Keith Tyler On

The karate.configure() method and the configure keyword relate back to a singleton object called ScenarioEngine. You can access this object from the karate object from within Javascript interop, via the getEngine() method, which in turn has a getConfig() method to access getters and setters for these values.

    * eval print(karate.getEngine().getConfig().getReadTimeout());
    * eval karate.configure("readTimeout",12345)
    * eval print(karate.getEngine().getConfig().getReadTimeout());

which will print:

30000
12345

showing the original default of 30000, and confirming the updated value of 12345. (This will work the exact same way using the configure keyword.)

You can use JS's Object.keys() to see all the available getter and setter methods for config values on the object returned by .config().