Class Runner.Builder
- Enclosing class:
Runner
-
Method Summary
Modifier and TypeMethodDescriptionbackupOutputDir(boolean enabled) Enable/disable backup of existing output directory.Build the Suite without running it.callOnceCacheStore(Map<String, Map<String, Object>> cacheStore, Map<String, ReentrantLock> lockStore) Inject pre-allocated callOnce/setupOnce stores (keyed by feature URI).callSingleCache(Map<String, Object> cache, ReentrantLock lock) Inject a pre-allocated callSingle cache (and its companion lock).captureStepLogs(boolean enabled) Collect each step's Karate output — HTTP request / response blocks,print— intoStepResult.log, which is what the HTML report, the JSONL / JUnit / Cucumber writers and karate-gatling's log replay all read.Set the directory containing karate-config.js.consoleLevel(String level) Set the SLF4J/console log level for the "karate" logger.<T> Runner.BuilderdebugSupport(io.karatelabs.js.RunInterceptor<T> interceptor, io.karatelabs.js.DebugPointFactory<T> factory) Set debug support with interceptor and factory.driverProvider(DriverProvider provider) Set a driver provider for managing browser driver lifecycle.dryRun(boolean enabled) Enable dry-run mode (parse but don't execute).Add Feature objects directly.features(Collection<Feature> values) Add Feature objects directly.Provisional API — may change or be removed without notice. Exposed to support advanced runtime scenario discovery (e.g. sequential retry against an expensive grid session) until in-suite orchestration hooks land.Bind a JS global (an ext-global-shaped object, typically aSimpleObject) into every scenario of this run — the run-free / programmatic equivalent of anExtcallingSuite.registerGlobal(String, Object)inonBoot.httpClientFactory(HttpClientFactory factory) Set the HTTP client factory for custom/mock HTTP clients.Set the karate environment (karate.env).listener(RunListener listener) Add a run event listener.listenerFactory(RunListenerFactory factory) Add a run listener factory for per-thread listeners.listenerFactory(String className) Add a run listener factory by class name (supports no-arg constructor).listeners(Collection<RunListener> values) Add multiple run event listeners.Set the minimum log level for report capture.Set the minimum log level by name (case-insensitive).outputConsoleSummary(boolean enabled) outputCucumberJson(boolean enabled) Enable/disable Cucumber JSON report generation.Set the output directory for reports.Set the output directory for reports.outputHtmlReport(boolean enabled) Enable/disable HTML report generation.outputJsonLines(boolean enabled) Enable/disable JSON Lines streaming output.outputJunitXml(boolean enabled) Enable/disable JUnit XML report generation.parallel(int threadCount) Execute the tests with the specified thread count.Add paths to search for .feature files.Add paths to search for .feature files.pool()Enable browser driver pooling for parallel UI tests.pool(int size) Enable browser driver pooling with explicit pool size.resultListener(ResultListener listener) Add a result listener for streaming test results.resultListeners(Collection<ResultListener> values) Add multiple result listeners.retainCallResults(boolean enabled) Keep the nestedkarate.call()result trees reachable after the run.retainStepLogs(boolean enabled) Keep each step's captured log text and embeds reachable after the run.scenarioName(String name) Filter by scenario name (exact match, whitespace-trimmed on both sides).skipTagFiltering(boolean skip) Skip tag filtering (@env, @ignore) so all scenarios run regardless of tags.systemProperty(String key, String value) Set a system property that will be available via karate.properties in scripts.Set tag filter expressions.toString()workingDir(String dir) Set the working directory for relative path resolution.workingDir(Path dir) Set the working directory for relative path resolution.
-
Method Details
-
path
Add paths to search for .feature files. Can be directories or individual files. -
path
Add paths to search for .feature files. -
features
Add Feature objects directly. -
features
Add Feature objects directly. -
karateEnv
Set the karate environment (karate.env). -
tags
Set tag filter expressions. Multiple arguments are AND-ed together (each must match). Commas within a single argument mean OR (any must match).Examples:
tags("@smoke")— run scenarios tagged @smoketags("~@slow")— exclude scenarios tagged @slowtags("@smoke,@fast")— run scenarios tagged @smoke OR @fasttags("~@slow", "~@ignore")— exclude @slow AND @ignoretags("@smoke", "~@slow")— must have @smoke AND must not have @slow
-
scenarioName
Filter by scenario name (exact match, whitespace-trimmed on both sides). When set, only scenarios whose name equals this value will run, and tag filters (@ignore, @env) are bypassed for matches — the same semantics as thefile.feature:LINEline filter. -
configDir
Set the directory containing karate-config.js. -
systemProperty
Set a system property that will be available via karate.properties in scripts. Multiple properties can be set by calling this method multiple times. -
logLevel
Set the minimum log level for report capture. Logs below this level will be filtered from reports. -
logLevel
Set the minimum log level by name (case-insensitive). Valid values: trace, debug, info, warn, error -
consoleLevel
Set the SLF4J/console log level for the "karate" logger. Distinct fromlogLevel(String)which is the report-buffer threshold. Valid values: trace, debug, info, warn, error. If null/unset the level is inherited from logback.xml (typically INFO). -
outputDir
Set the output directory for reports. -
outputDir
Set the output directory for reports. -
workingDir
Set the working directory for relative path resolution. This affects how feature file paths are displayed in reports. -
workingDir
Set the working directory for relative path resolution. This affects how feature file paths are displayed in reports. -
outputHtmlReport
Enable/disable HTML report generation. -
outputJsonLines
Enable/disable JSON Lines streaming output. Streams lifecycle events to karate-json/karate-events.jsonl as they fire, with one record per line and a per-line flush so external tools (e.g. IDE test runners) can tail the file in real time. -
outputJunitXml
Enable/disable JUnit XML report generation. -
outputCucumberJson
Enable/disable Cucumber JSON report generation. -
backupOutputDir
Enable/disable backup of existing output directory. When enabled, the existing output directory is renamed with a timestamp suffix (e.g., karate-reports_2025-01-15_143022) before new reports are written. -
retainCallResults
Keep the nestedkarate.call()result trees reachable after the run.Off by default. Every call attaches the callee's whole result tree to the calling step, and the suite holds every feature until it ends, so retaining them makes memory scale with total scenarios times calls per scenario — enough to exhaust the heap on a long suite. They are released once each feature has completed and every listener has consumed it.
Reports are unaffected either way: the HTML report extracts its page model, nested step detail included, while the result is still whole. Turn this on only to walk into a called feature's steps from a
SuiteResultprogrammatically after the run. -
retainStepLogs
Keep each step's captured log text and embeds reachable after the run.Off by default. The log holds the rendered HTTP request and response for every step and an embed holds raw bytes — a screenshot, a document — and the suite holds every feature until it ends, so retaining them makes memory scale with total steps times payload size. They are released once each feature has completed and every listener has consumed it.
Reports are unaffected either way: HTML, Cucumber JSON, JUnit XML and the JSONL stream all serialize the feature while it is still whole. Turn this on only to read
StepResult.getLog()orgetEmbeds()from aSuiteResultprogrammatically after the run.Ignored under karate-gatling, where nothing is retained past one execution anyway and
logReplayreads the log after the feature returns. -
outputConsoleSummary
-
captureStepLogs
Collect each step's Karate output — HTTP request / response blocks,print— intoStepResult.log, which is what the HTML report, the JSONL / JUnit / Cucumber writers and karate-gatling's log replay all read.Unset by default, which means on for a normal run and off under Gatling: that lane writes no HTML report, so the text would be built — the response body re-parsed and pretty-printed for every request — only to be retained and discarded. Set it explicitly to override in either direction.
This is capture, not logging:
printandkarate.log()reach SLF4J either way, at whatever level the Logback config allows. -
dryRun
Enable dry-run mode (parse but don't execute). -
global
Bind a JS global (an ext-global-shaped object, typically aSimpleObject) into every scenario of this run — the run-free / programmatic equivalent of anExtcallingSuite.registerGlobal(String, Object)inonBoot. Lets an embedder stand up a one-offRunner.features(...)run that binds a global without authoring an ext or akarate-boot.js— e.g. a synthesizer whose single synthetic step replays recorded events through. Seeded beforeinvalid reference
LogContext#stepkarate-config.js; a reserved-name collision fails the suite loud at construction. -
listener
Add a run event listener. -
listeners
Add multiple run event listeners. -
listenerFactory
Add a run listener factory for per-thread listeners. The factory's create() method is called once per execution thread. -
listenerFactory
Add a run listener factory by class name (supports no-arg constructor). Used for CLI --listener-factory option.- Parameters:
className- fully qualified class name
-
resultListener
Add a result listener for streaming test results. -
resultListeners
Add multiple result listeners. -
driverProvider
Set a driver provider for managing browser driver lifecycle.When set, the provider is used to acquire/release drivers for scenarios instead of creating a new driver per scenario.
Example:
Runner.path("features/") .driverProvider(new PooledDriverProvider()) .parallel(4); // Pool size auto-detected -
pool
Enable browser driver pooling for parallel UI tests. Creates a PooledDriverProvider that reuses browser instances across scenarios.Pool size is auto-detected from the parallel thread count.
Example:
Runner.path("features/") .pool() // Enable pooling .parallel(4); // Pool size = 4 -
pool
Enable browser driver pooling with explicit pool size. Creates a PooledDriverProvider that reuses browser instances across scenarios.Example:
Runner.path("features/") .pool(2) // Pool of 2 browsers .parallel(4); // 4 threads share 2 browsers- Parameters:
size- number of browser instances to pool
-
httpClientFactory
Set the HTTP client factory for custom/mock HTTP clients. When set, this factory is used instead of the default HTTP client. -
skipTagFiltering
Skip tag filtering (@env, @ignore) so all scenarios run regardless of tags. Use this for unit tests that need to run scenarios with any tags. -
debugSupport
public <T> Runner.Builder debugSupport(io.karatelabs.js.RunInterceptor<T> interceptor, io.karatelabs.js.DebugPointFactory<T> factory) Set debug support with interceptor and factory. Used for IDE debugging integration. -
callSingleCache
Inject a pre-allocated callSingle cache (and its companion lock). When set, Suites built from this builder reuse the cache instead of creating their own — so the cache outlives any single Suite. Used by karate-gatling to share callSingle results across the virtual users of one simulation.Pass a matching
lockso all Suites sharing the cache also share its write lock; otherwise concurrent virtual users can race. -
callOnceCacheStore
public Runner.Builder callOnceCacheStore(Map<String, Map<String, Object>> cacheStore, Map<String, ReentrantLock> lockStore) Inject pre-allocated callOnce/setupOnce stores (keyed by feature URI). Same lifetime semantics ascallSingleCache— used by karate-gatling so a feature's callOnce/setupOnce runs once per simulation, not once per virtual user. -
setupOnceCacheStore
-
getResolvedFeatures
Provisional API — may change or be removed without notice. Exposed to support advanced runtime scenario discovery (e.g. sequential retry against an expensive grid session) until in-suite orchestration hooks land.Note: callers that filter the returned
Features themselves (e.g. by walking sections and evaluating aTagSelector) bypassFeatureRuntime.shouldSelectand will miss@ignore,@setup, suite-level line/name filters, and@envnot. Mirror that logic if you need parity with what would actually run. -
parallel
Execute the tests with the specified thread count. This is the terminal operation that runs the tests.- Parameters:
threadCount- number of threads (1 for sequential)- Returns:
- the test results
-
buildSuite
Build the Suite without running it. Useful for advanced scenarios where you need to configure the Suite further or run it manually. -
toString
-