Interface ExtGlobalFactory

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface ExtGlobalFactory
Mints a per-scenario ext-global instance, bound fresh into each scenario's JS scope. The alternative Suite.registerGlobal(String, Object) registers one shared singleton for the whole Suite — correct for stateless helpers, but unsafe for an ext whose object carries per-scenario mutable state (e.g. image.threshold = 0.02) under parallel execution, since every scenario would mutate the same instance.

Registering a factory instead (see Suite.registerGlobal(String, ExtGlobalFactory)) gives each scenario its own instance, created at seed time with the scenario's KarateJsContext in hand — mirroring how karate.channel('kafka') receives the runtime at creation. Through the context the instance can resolve this: / classpath: / file: paths (KarateJsContext.getWorkingDir() → Resource.resolve(String)), reach the ScenarioRuntime, and read KarateConfig — without any thread-local or shared state.

Seeded in ScenarioRuntime init before karate-config.js runs, exactly like the singleton form, so the per-scenario instance is visible to config and to every step.

  • Method Summary

    Modifier and Type
    Method
    Description
    Create the ext-global instance for one scenario.
  • Method Details

    • create

      Object create(KarateJsContext context)
      Create the ext-global instance for one scenario.
      Parameters:
      context - the scenario's runtime context (path resolution, runtime, config); never null at seed time
      Returns:
      the object bound into JS scope under the registered name (typically a SimpleObject)