Package io.karatelabs.core
Class KarateJs
java.lang.Object
io.karatelabs.core.KarateJs
- All Implemented Interfaces:
PerfContext,io.karatelabs.js.ObjectLike,io.karatelabs.js.SimpleObject
Main implementation of the karate.* JavaScript API.
This class contains methods that require stateful access to:
- The JavaScript engine (for variable lookup and evaluation)
- Runtime context via KarateJsContext (scenario, feature, config)
- HTTP client and resource resolution
- Mock handler context
Stateless utility methods are delegated to KarateJsUtils.
Shared state and infrastructure are inherited from KarateJsBase.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal HttpClientfinal io.karatelabs.js.Enginefinal HttpRequestBuilderfinal io.karatelabs.common.ResourceFields inherited from interface io.karatelabs.js.SimpleObject
TO_STRING -
Constructor Summary
ConstructorsConstructorDescriptionKarateJs(io.karatelabs.common.Resource root) KarateJs(io.karatelabs.common.Resource root, HttpClient client) KarateJs(io.karatelabs.common.Resource root, HttpClientFactory factory) -
Method Summary
Modifier and TypeMethodDescriptionvoidcapturePerfEvent(String name, long startTime, long endTime) Capture a custom performance event (implements PerfContext).Renders an HTML template and returns the result.markup()Lazy-initialize and return the Markup template engine.voidsetContext(KarateJsContext context) voidvoidsetMockHandler(MockHandler handler) voidvoidsetOnMatch(BiConsumer<io.karatelabs.js.Context, Result> onMatch) voidsetOutputDir(String outputDir) voidsetPrevRequest(HttpRequest request) Track the previous HTTP request for karate.prevRequest.voidsetResourceResolver(ResourceResolver resourceResolver) 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
getPrototypeMethods inherited from interface io.karatelabs.js.SimpleObject
getMember, jsKeys, jsToString, putMember, removeMember, toMap
-
Field Details
-
root
public final io.karatelabs.common.Resource root -
engine
public final io.karatelabs.js.Engine engine -
client
-
http
-
-
Constructor Details
-
KarateJs
public KarateJs(io.karatelabs.common.Resource root) -
KarateJs
-
KarateJs
-
-
Method Details
-
setPrevRequest
Track the previous HTTP request for karate.prevRequest. Called by HttpRequestBuilder after successful HTTP calls. -
capturePerfEvent
Capture a custom performance event (implements PerfContext).When running under Gatling, this event will be reported to the statistics engine. When not in performance mode, this is a no-op.
Usage in Java helpers:
public static Object myRpc(Map args, PerfContext karate) { long start = System.currentTimeMillis(); // ... custom logic ... long end = System.currentTimeMillis(); karate.capturePerfEvent("myRpc", start, end); return result; }- Specified by:
capturePerfEventin interfacePerfContext- Parameters:
name- the event name for Gatling reportsstartTime- the start time in epoch millisecondsendTime- the end time in epoch milliseconds
-
markup
Lazy-initialize and return the Markup template engine. Used for doc() and render() template processing. -
doc
Renders an HTML template and returns the result. Also sends to onDoc consumer if set. Called by the 'doc' keyword in StepExecutor. -
jsGet
- Specified by:
jsGetin interfaceio.karatelabs.js.SimpleObject
-
setOnDoc
-
setResourceResolver
-
setOnMatch
-
setContext
-
setEnv
-
setMockHandler
-
setOutputDir
-