Class BootBinding
boot global exposed inside karate-boot.js.
karate-boot.js is ext-scripting only — its JS scope is discarded after the file evaluates, so variables defined there cannot leak into the feature-runtime scope. The only API surface is this class. See AGENT_KARATE.md K43.
boot.env— the value ofkarate.env(CLI-eflag).boot.sysenv(name)/boot.sysenv(name, default)— read an OS environment variable, optionally falling back to a default when unset or empty.boot.sysprop(name)/boot.sysprop(name, default)— read a JVM system property; reads from the Suite's merged property map when available.boot.classpath(dir)— declare the resource root: where aclasspath:miss falls back to, and (Runner lane) what the working dir re-anchors on.boot.read(path)— read a file on the unified reference rule (leading/anchors the project root).boot.log(msg)— INFO log line, prefixed[boot].boot.ext(name)— resolve + construct the named ext via theio.karatelabs.ext.<name>.<Name>Extconvention, fire itsExt.onBoot(Suite), register it with the Suite, and return the instance so the boot script can configure it.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor for tests + advanced callers — decouples the root + listener registration from a fully-instantiated Suite (the production caller,BootLoader.evalIfPresent(io.karatelabs.core.Suite, java.nio.file.Path, java.lang.String), runs while the Suite is still being built). -
Method Summary
Modifier and TypeMethodDescriptionvoidboot.classpath('src/test/resources')— declare the resource root: the directory aclasspath:reference retries against when the classloader misses, and (in a Java Runner-lane run that did not set an explicit working dir) the directory the working dir re-anchors to.boot.ext('name')— resolve + construct + register an ext.The directory declared byclasspath(String), root-relative and de-slashed, ornullwhen the project declared nothing (then the fallback dir IS the root).getEnv()boot.env— JS sees this as a property, not a method.getExts()The ext globals registered during boot (each ext'sonBootran eagerly inext(java.lang.String), e.g.booleanboot.has('name')— is this ext available to boot?voidboot.log('...')— INFO log with [boot] prefix.Collected manifest array shape for SUITE_ENTER.data.exts[].boot.read('path')— read a text file, on the one unified rule: a leading/anchors THE project root, a bare ref is root-relative,classpath:is classloader-first then theclasspath(String)fallback, andfile:is a host path.boot.sysenv('NAME')— read an OS env var; null if unset.boot.sysenv('NAME', 'default')— read an OS env var, falling back todefaultValuewhen unset or empty (shell${VAR:-default}semantics).boot.sysprop('NAME')— read a JVM system property; null if unset.boot.sysprop('NAME', 'default')— read a JVM system property, falling back todefaultValuewhen unset or empty.
-
Constructor Details
-
BootBinding
Constructor for tests + advanced callers — decouples the root + listener registration from a fully-instantiated Suite (the production caller,BootLoader.evalIfPresent(io.karatelabs.core.Suite, java.nio.file.Path, java.lang.String), runs while the Suite is still being built).- Parameters:
root- THE project root everyboot.*reference resolves against
-
-
Method Details
-
getEnv
boot.env— JS sees this as a property, not a method. -
sysenv
boot.sysenv('NAME')— read an OS env var; null if unset. -
sysenv
boot.sysenv('NAME', 'default')— read an OS env var, falling back todefaultValuewhen unset or empty (shell${VAR:-default}semantics). Collapses the previousboot.sysenv('FOO') || 'default'idiom into a single call. -
sysprop
boot.sysprop('NAME')— read a JVM system property; null if unset. -
sysprop
boot.sysprop('NAME', 'default')— read a JVM system property, falling back todefaultValuewhen unset or empty. Reads from the Suite's merged property map when available soRunner.Builder.systemProperties(...)injections are visible, otherwise falls back toSystem.getProperty(String). -
classpath
boot.classpath('src/test/resources')— declare the resource root: the directory aclasspath:reference retries against when the classloader misses, and (in a Java Runner-lane run that did not set an explicit working dir) the directory the working dir re-anchors to. One committed line makes a Maven/Gradle project resolve its references identically under a JVM run — where the classloader hits and this mapping stays inert — and under a bare-folder serve run, where the fallback carriesclasspath:refs to the declared dir.The argument is a root-relative reference, so
file:/classpath:/this:and Windows drive-letter absolutes are rejected.''is valid and means the root itself (the "unify only, map nothing" spelling) — which is also what an undeclared project gets, so a bare-folder project never needs this call. Last call wins. -
getClasspathDir
The directory declared byclasspath(String), root-relative and de-slashed, ornullwhen the project declared nothing (then the fallback dir IS the root). -
read
boot.read('path')— read a text file, on the one unified rule: a leading/anchors THE project root, a bare ref is root-relative,classpath:is classloader-first then theclasspath(String)fallback, andfile:is a host path. Declareboot.classpath(...)before reading aclasspath:ref that is not on the real classpath. -
log
boot.log('...')— INFO log with [boot] prefix. -
ext
boot.ext('name')— resolve + construct + register an ext.Resolution by name convention:
'openapi'→io.karatelabs.ext.openapi.OpenapiExt. The class is loaded from the runtime classloader; missing ext → boot-time failure (suite fails loud).Same name twice returns the same singleton instance.
-
has
boot.has('name')— is this ext available to boot? A pure classpath probe using the same name convention asext(String); constructs nothing and registers nothing.Exists because
boot.extis deliberately strict — a typo, or a missing ext the project genuinely depends on, must fail the suite loudly. But a project may legitimately depend on an ext only when it is present: a kit whose gRPC/Kafka beat is optional still has to run on a runtime that ships without those leaves. Before this, the only way to express that was an external switch (an env var) — which the project cannot see, cannot default correctly, and which nobody driving the console can set, so the whole project would fail to boot with an error naming a class rather than the switch.if (boot.has('grpc')) { … }lets the project decide for itself.An already-booted ext reports
truewithout a class lookup. -
getExts
-
getGlobals
The ext globals registered during boot (each ext'sonBootran eagerly inext(java.lang.String), e.g. RulesExt'sRule/Schema/matchinstances + aCheckfactory) — the seedable scenario globals a caller OUTSIDE a run can apply to its own engine to reach an ext the same way a real run'sScenarioRuntimedoes (it seeds this very map). A value is a shared singleton instance, or anExtGlobalFactorythe caller mints per-context. Empty when no boot file ran. -
manifests
Collected manifest array shape for SUITE_ENTER.data.exts[].
-