Class KarateConfig

java.lang.Object
io.karatelabs.core.KarateConfig
All Implemented Interfaces:
io.karatelabs.js.ObjectLike, io.karatelabs.js.SimpleObject

public class KarateConfig extends Object implements io.karatelabs.js.SimpleObject
Holds runtime configuration settings set via the 'configure' keyword.

This is distinct from:

  • KaratePom - Project file (karate-pom.json) for CLI options
  • karate-config.js - Runtime bootstrap that runs per-scenario

Example usage:

 * configure ssl = true
 * configure proxy = 'http://proxy:8080'
 * configure readTimeout = 60000
 * def cfg = karate.config
 * match cfg.sslEnabled == true
 

Implements SimpleObject so it can be accessed as a JavaScript object via karate.config.

  • Constructor Details

    • KarateConfig

      public KarateConfig()
  • Method Details

    • copy

      public KarateConfig copy()
      Create a deep copy of this configuration. Used to snapshot config state for callonce/callSingle isolation.
      Returns:
      a new KarateConfig with copied values
    • copyFrom

      public void copyFrom(KarateConfig other)
      Copy all configuration values from another KarateConfig. Used to propagate config changes from called features back to the caller.
      Parameters:
      other - the source config to copy from
    • copyChangedFrom

      public void copyChangedFrom(KarateConfig before, KarateConfig after)
      Three-way merge used when a cached callonce result is replayed into a later scenario. Only the keys the callee actually changed are applied — that is, the ones that differ between the before and after snapshots taken around the one real execution. Everything else keeps this config's current (per-scenario) value.

      A wholesale copyFrom(KarateConfig) would also stamp the *caller's* state at the time of that first execution over every later scenario. That is invisible for plain data but wrong for values that are JS functions - a lifecycle hook or a configure headers function is re-created per scenario by karate-config.js and is bound to that scenario's JS context. Replaying the first scenario's instance made every later afterScenario hook read the first scenario's variables (e.g. karate.get('response') stayed frozen).

      Known limitation: this diffs by value, where StepUtils.calleeDelta(java.util.Map<java.lang.String, java.lang.Object>, java.util.Map<java.lang.String, java.lang.Object>) diffs variables by identity. So a callee that sets a key to exactly the value the caller already had at that moment is indistinguishable from a callee that left it alone, and later scenarios keep their own value for it. Reaching that needs config that varies per scenario (an outline row) plus a callee setting the same key to one row's value - narrow enough to leave alone; closing it would mean tracking which keys were explicitly configured rather than comparing values.

      Parameters:
      before - config snapshot taken just before the cached execution ran
      after - config snapshot taken just after it completed
    • configure

      public void configure(String key, Object value)
      Apply configuration from a key-value pair.

      This used to return whether the HTTP client needed rebuilding, and callers gated HttpClient.apply on it. Classifying by key cannot be done correctly here: the verdict was wrong for retry (which changes a setting baked into the client at build time) and for auth switching away from NTLM (which leaves stale credentials), and it could say nothing at all about the three paths that copy a whole config across a scenario boundary. HttpClient.apply is idempotent by contract and decides for itself; hand it the config and let it answer.

      Parameters:
      key - the configure key (e.g., "ssl", "proxy", "readTimeout")
      value - the value to set
      Throws:
      RuntimeException - if key is not recognized
    • applyLoggingToContext

      public void applyLoggingToContext(LogContext ctx)
      Push this config's logging settings into the given LogContext. Called by ScenarioRuntime.call() after it allocates a fresh thread-local LogContext, so any mask / pretty values set in karate-config.js (or a prior step) survive into the scenario's HTTP logging.
    • getCompiledMask

      public LogMask getCompiledMask()
      Compiled HTTP log mask. Source of truth — LogContext mirrors this for per-thread reads by HttpLogger.
    • jsKeys

      public Collection<String> jsKeys()
      Specified by:
      jsKeys in interface io.karatelabs.js.SimpleObject
    • jsGet

      public Object jsGet(String name)
      Specified by:
      jsGet in interface io.karatelabs.js.SimpleObject
    • getUrl

      public String getUrl()
    • getReadTimeout

      public int getReadTimeout()
    • getConnectTimeout

      public int getConnectTimeout()
    • isFollowRedirects

      public boolean isFollowRedirects()
    • getLocalAddress

      public String getLocalAddress()
    • getCharset

      public Charset getCharset()
    • getSsl

      public Map<String,Object> getSsl()
    • isSslEnabled

      public boolean isSslEnabled()
    • getSslAlgorithm

      public String getSslAlgorithm()
    • getSslKeyStore

      public String getSslKeyStore()
    • getSslKeyStorePassword

      public String getSslKeyStorePassword()
    • getSslKeyStoreType

      public String getSslKeyStoreType()
    • getSslTrustStore

      public String getSslTrustStore()
    • getSslTrustStorePassword

      public String getSslTrustStorePassword()
    • getSslTrustStoreType

      public String getSslTrustStoreType()
    • isSslTrustAll

      public boolean isSslTrustAll()
    • getProxy

      public Map<String,Object> getProxy()
    • getProxyUri

      public String getProxyUri()
    • getProxyUsername

      public String getProxyUsername()
    • getProxyPassword

      public String getProxyPassword()
    • getNonProxyHosts

      public List<String> getNonProxyHosts()
    • getNtlmAuth

      public Map<String,Object> getNtlmAuth()
    • getNtlmUsername

      public String getNtlmUsername()
    • getNtlmPassword

      public String getNtlmPassword()
    • getNtlmDomain

      public String getNtlmDomain()
    • getNtlmWorkstation

      public String getNtlmWorkstation()
    • getAuth

      public Map<String,Object> getAuth()
    • getAuthType

      public String getAuthType()
    • getAuthUsername

      public String getAuthUsername()
    • getAuthPassword

      public String getAuthPassword()
    • getAuthToken

      public String getAuthToken()
    • getAuthAccessTokenUrl

      public String getAuthAccessTokenUrl()
    • getAuthClientId

      public String getAuthClientId()
    • getAuthClientSecret

      public String getAuthClientSecret()
    • getAuthScope

      public String getAuthScope()
    • getRetry

      public Map<String,Object> getRetry()
    • getRetryInterval

      public int getRetryInterval()
    • getRetryCount

      public int getRetryCount()
    • getReport

      public Map<String,Object> getReport()
    • isShowLog

      public boolean isShowLog()
    • isShowAllSteps

      public boolean isShowAllSteps()
    • getLogging

      public Map<String,Object> getLogging()
    • getLoggingReportLevel

      public String getLoggingReportLevel()
    • getLoggingConsoleLevel

      public String getLoggingConsoleLevel()
    • isLoggingPretty

      public boolean isLoggingPretty()
    • getCallSingleCache

      public Map<String,Object> getCallSingleCache()
    • getCallSingleCacheMinutes

      public int getCallSingleCacheMinutes()
    • getCallSingleCacheDir

      public String getCallSingleCacheDir()
    • getHeaders

      public Object getHeaders()
    • getCookies

      public Object getCookies()
    • isHttpRetryEnabled

      public boolean isHttpRetryEnabled()
    • isContinueOnStepFailure

      public boolean isContinueOnStepFailure()
    • isAbortedStepsShouldPass

      public boolean isAbortedStepsShouldPass()
    • isAbortSuiteOnFailure

      public boolean isAbortSuiteOnFailure()
    • isMatchEachEmptyAllowed

      public boolean isMatchEachEmptyAllowed()
    • isCorsEnabled

      public boolean isCorsEnabled()
    • getResponseHeaders

      public Object getResponseHeaders()
    • getBeforeScenario

      public Object getBeforeScenario()
    • getAfterScenario

      public Object getAfterScenario()
    • getAfterScenarioOutline

      public Object getAfterScenarioOutline()
    • getAfterFeature

      public Object getAfterFeature()
    • getOnStepFailure

      public Object getOnStepFailure()
    • getDriverConfig

      public Object getDriverConfig()