Class KarateConfig
- All Implemented Interfaces:
io.karatelabs.js.ObjectLike,io.karatelabs.js.SimpleObject
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.
-
Field Summary
Fields inherited from interface io.karatelabs.js.SimpleObject
TO_STRING -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidPush this config's logging settings into the given LogContext.voidApply configuration from a key-value pair.copy()Create a deep copy of this configuration.voidcopyChangedFrom(KarateConfig before, KarateConfig after) Three-way merge used when a cachedcallonceresult is replayed into a later scenario.voidcopyFrom(KarateConfig other) Copy all configuration values from another KarateConfig.getAuth()intCompiled HTTP log mask.intgetProxy()intgetRetry()intintgetSsl()getUrl()booleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanjsKeys()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.karatelabs.js.ObjectLike
getMember, getPrototype, isExtensible, isFrozen, isOwnProperty, isSealed, putMember, removeMember, setExtensible, setFrozen, setSealedMethods inherited from interface io.karatelabs.js.SimpleObject
getMember, jsToString, putMember, removeMember, toMap
-
Constructor Details
-
KarateConfig
public KarateConfig()
-
-
Method Details
-
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
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
Three-way merge used when a cachedcallonceresult is replayed into a later scenario. Only the keys the callee actually changed are applied — that is, the ones that differ between thebeforeandaftersnapshots 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 aconfigure headersfunction 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 laterafterScenariohook 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 ranafter- config snapshot taken just after it completed
-
configure
Apply configuration from a key-value pair.This used to return whether the HTTP client needed rebuilding, and callers gated
HttpClient.applyon it. Classifying by key cannot be done correctly here: the verdict was wrong forretry(which changes a setting baked into the client at build time) and forauthswitching 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.applyis 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
Push this config's logging settings into the given LogContext. Called byScenarioRuntime.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
Compiled HTTP log mask. Source of truth —LogContextmirrors this for per-thread reads byHttpLogger. -
jsKeys
- Specified by:
jsKeysin interfaceio.karatelabs.js.SimpleObject
-
jsGet
- Specified by:
jsGetin interfaceio.karatelabs.js.SimpleObject
-
getUrl
-
getReadTimeout
public int getReadTimeout() -
getConnectTimeout
public int getConnectTimeout() -
isFollowRedirects
public boolean isFollowRedirects() -
getLocalAddress
-
getCharset
-
getSsl
-
isSslEnabled
public boolean isSslEnabled() -
getSslAlgorithm
-
getSslKeyStore
-
getSslKeyStorePassword
-
getSslKeyStoreType
-
getSslTrustStore
-
getSslTrustStorePassword
-
getSslTrustStoreType
-
isSslTrustAll
public boolean isSslTrustAll() -
getProxy
-
getProxyUri
-
getProxyUsername
-
getProxyPassword
-
getNonProxyHosts
-
getNtlmAuth
-
getNtlmUsername
-
getNtlmPassword
-
getNtlmDomain
-
getNtlmWorkstation
-
getAuth
-
getAuthType
-
getAuthUsername
-
getAuthPassword
-
getAuthToken
-
getAuthAccessTokenUrl
-
getAuthClientId
-
getAuthClientSecret
-
getAuthScope
-
getRetry
-
getRetryInterval
public int getRetryInterval() -
getRetryCount
public int getRetryCount() -
getReport
-
isShowLog
public boolean isShowLog() -
isShowAllSteps
public boolean isShowAllSteps() -
getLogging
-
getLoggingReportLevel
-
getLoggingConsoleLevel
-
isLoggingPretty
public boolean isLoggingPretty() -
getCallSingleCache
-
getCallSingleCacheMinutes
public int getCallSingleCacheMinutes() -
getCallSingleCacheDir
-
getHeaders
-
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
-
getBeforeScenario
-
getAfterScenario
-
getAfterScenarioOutline
-
getAfterFeature
-
getOnStepFailure
-
getDriverConfig
-