Interface Ext
- All Superinterfaces:
RunListener
RunListener.
Exts are loaded from a karate-boot.js file at the workdir root, once per
Suite, by BootLoader. Activation example:
// karate-boot.js
const openapi = boot.ext('openapi');
openapi.path = 'api/openapi.yaml';
openapi.excludes = ['/health/**'];
The boot.ext('foo') call resolves foo to
io.karatelabs.ext.foo.FooExt by name convention, instantiates the class,
invokes onBoot(Suite) immediately, registers the ext as a listener on the
Suite, and returns the instance so the boot script can configure it.
Exts coexist with the per-call channel
pattern (karate.channel(...)) — channels are per-call; exts are
singleton-per-Suite. See AGENT_KARATE.md K43 for the design rationale.
Lifecycle:
karate-boot.jsevaluates → eachboot.ext('name')call constructs the ext and firesonBoot(Suite).- Suite registers the ext as a
RunListener; it sees every event. SUITE_ENTER.data.exts[]carries each ext'sgetManifest().- After
SUITE_EXIT,onShutdown()fires.
Failure mode: exceptions during onBoot fail the Suite loudly. Exceptions
inside onEvent(io.karatelabs.core.RunEvent) are logged WARN and dropped — the run continues, that one
signal is lost.
-
Method Summary
Modifier and TypeMethodDescriptionManifest entry recorded underSUITE_ENTER.data.exts[]so receivers know which exts were active for this run and with what config.default voidCalled once per Suite when theboot.ext('name')expression evaluates inkarate-boot.js.default booleanDefaultRunListener.onEvent(RunEvent)returns true (continue execution).default voidCalled afterSUITE_EXITfires.default booleanAn ext whose output is computed from thekarate-events.jsonlstream (e.g. a coverage analyzer) returnstrueso the Suite auto-enables the JSONL event writer — exactly as if-f karate:jsonl/Runner...outputJsonLines(true)had been passed.
-
Method Details
-
onBoot
Called once per Suite when theboot.ext('name')expression evaluates inkarate-boot.js. Throws from here fail the Suite.The Suite is still under construction here — boot runs before config discovery and feature resolution, because
boot.classpath(dir)is what those honour.Suite.getRoot()is final and is the anchor an ext must resolve its configured paths against;Suite.getWorkingDir(),Suite.featuresand theconfig*Resourcefields are not yet assigned. Resolve lazily (at first use, or fromonEvent) if you need anything beyond the root.Default no-op so exts that only need to observe events (
onEvent) can stay terse. -
onShutdown
default void onShutdown()Called afterSUITE_EXITfires. Use to release file handles, flush buffers, etc. Exceptions are logged and dropped. -
requiresJsonlEvents
default boolean requiresJsonlEvents()An ext whose output is computed from thekarate-events.jsonlstream (e.g. a coverage analyzer) returnstrueso the Suite auto-enables the JSONL event writer — exactly as if-f karate:jsonl/Runner...outputJsonLines(true)had been passed. Without this, a run that boots such an ext would pass green yet silently produce none of the ext's output. Evaluated once, afterkarate-boot.jsevaluation and before the writer is wired. -
getManifest
Manifest entry recorded underSUITE_ENTER.data.exts[]so receivers know which exts were active for this run and with what config. Returned map is serialised to JSON verbatim — keep keys primitive (String,Number,Boolean, nested maps).Standard entries:
name,version. Ext-specific summary fields are flat under the top-level map. Default returns an empty map; exts with meaningful manifests should override. -
onEvent
DefaultRunListener.onEvent(RunEvent)returns true (continue execution). Exts that only need lifecycle hooks (onBoot / onShutdown / manifest) without observing events can rely on this and skip the override.- Specified by:
onEventin interfaceRunListener- Parameters:
event- the event containing type, runtime objects, and results- Returns:
- true to continue execution, false to skip (only meaningful for *_ENTER events)
-