Class BootBinding

java.lang.Object
io.karatelabs.core.BootBinding

public class BootBinding extends Object
Backing object for the 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 of karate.env (CLI -e flag).
  • 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 a classpath: 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 the io.karatelabs.ext.<name>.<Name>Ext convention, fire its Ext.onBoot(Suite), register it with the Suite, and return the instance so the boot script can configure it.
  • Constructor Details

  • Method Details

    • getEnv

      public String getEnv()
      boot.env — JS sees this as a property, not a method.
    • sysenv

      public String sysenv(String name)
      boot.sysenv('NAME') — read an OS env var; null if unset.
    • sysenv

      public String sysenv(String name, String defaultValue)
      boot.sysenv('NAME', 'default') — read an OS env var, falling back to defaultValue when unset or empty (shell ${VAR:-default} semantics). Collapses the previous boot.sysenv('FOO') || 'default' idiom into a single call.
    • sysprop

      public String sysprop(String name)
      boot.sysprop('NAME') — read a JVM system property; null if unset.
    • sysprop

      public String sysprop(String name, String defaultValue)
      boot.sysprop('NAME', 'default') — read a JVM system property, falling back to defaultValue when unset or empty. Reads from the Suite's merged property map when available so Runner.Builder.systemProperties(...) injections are visible, otherwise falls back to System.getProperty(String).
    • classpath

      public void classpath(String dir)
      boot.classpath('src/test/resources') — declare the resource root: the directory a classpath: 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 carries classpath: 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

      public String getClasspathDir()
      The directory declared by classpath(String), root-relative and de-slashed, or null when the project declared nothing (then the fallback dir IS the root).
    • read

      public String read(String path)
      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 the classpath(String) fallback, and file: is a host path. Declare boot.classpath(...) before reading a classpath: ref that is not on the real classpath.
    • log

      public void log(Object msg)
      boot.log('...') — INFO log with [boot] prefix.
    • ext

      public Ext ext(String name)
      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

      public boolean has(String name)
      boot.has('name') — is this ext available to boot? A pure classpath probe using the same name convention as ext(String); constructs nothing and registers nothing.

      Exists because boot.ext is 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 true without a class lookup.

    • getExts

      public Set<Ext> getExts()
    • getGlobals

      public Map<String,Object> getGlobals()
      The ext globals registered during boot (each ext's onBoot ran eagerly in ext(java.lang.String), e.g. RulesExt's Rule/Schema/match instances + a Check factory) — 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's ScenarioRuntime does (it seeds this very map). A value is a shared singleton instance, or an ExtGlobalFactory the caller mints per-context. Empty when no boot file ran.
    • manifests

      public List<Map<String,Object>> manifests()
      Collected manifest array shape for SUITE_ENTER.data.exts[].