GET STARTED
What's New in Karate v2
Karate v2 is a complete ground-up rewrite with significant improvements across the board. Most existing v1 tests work with just a dependency update — see the Migration Guide.
Performance & Scalability
Embedded JavaScript Engine
Karate v2 replaces GraalJS with a fast, hand-rolled JavaScript engine (karate-js) with ES6+ support, purpose-built for Java interop and thread-safe concurrent execution.
- No GraalVM dependency — works on any Java 21+ JVM
- Significantly faster for the Karate use-case (see benchmarks)
- Thread-safe by design for parallel test execution
Virtual Threads (Java 21+)
Karate v2 requires Java 21+ and leverages virtual threads for massive parallelism with minimal overhead. This means you can run hundreds of scenarios in parallel without tuning thread pools.
@lock Tag — Surgical Parallel Safety
The v1 @parallel=false tag was all-or-nothing: tagging a feature opted it out of parallel execution entirely, even when only one resource was actually contended. v2 replaces it with @lock, a fine-grained mutual-exclusion primitive that keeps the rest of your suite running in parallel.
@lock=database
Scenario: insert a user
# only one @lock=database scenario runs at a time
# unrelated scenarios continue in parallel
@lock=database
Scenario: delete a user
# waits for the @lock=database scenario above
@lock=*
Scenario: schema migration smoke
# exclusive — runs alone, nothing else in the suite is concurrent
@lock=<name>— named lock; only scenarios sharing the name serialize against each other. Two different lock names (e.g.@lock=dband@lock=cache) still run concurrently.@lock=*— exclusive lock; the scenario runs alone with no other scenarios concurrent. Use sparingly — it stalls the whole worker pool.- Place
@lockon aFeature:line to apply it to every scenario in that feature — a drop-in for v1's feature-level@parallel=false.
The result: virtual-thread parallelism stays maximally effective, and you only pay the serialization cost where it's actually needed. See Controlling Parallelism with @lock.
The v1 @parallel=false tag is no longer recognized in v2. Replace it with @lock=<name> (or @lock=*). See Migration from v1.
Assertions & Test Data
match within
Assert that a numeric value falls within a range:
* match response.temperature within { low: 36.0, high: 37.5 }
* match response.score !within { low: 0, high: 50 }
karate.faker.*
Built-in test data generation — no external libraries needed:
* def name = karate.faker.firstName()
* def email = karate.faker.email()
* def id = karate.faker.randomInt()
* def phone = karate.faker.phone()
karate.expect() — Chai-style Assertions
Familiar BDD-style assertions for teams migrating from Postman or Mocha:
karate.expect(response.name).to.equal('John')
karate.expect(response.age).to.be.above(18)
karate.expect(response).to.have.property('email')
karate.expect(response.tags).to.include('active')
karate.uuid()
Generate random UUIDs:
* def id = karate.uuid()
Complete diffs for failed match
A single match against a JSON (or XML) value now reports every mismatched path in one error — not just the first one it finds. Each diff lists the path, the actual value, and the expected value, with type annotations so type drift is obvious:
match failed: EQUALS
$ | not equal | match failed for names: [a, b] (MAP:MAP)
{"a":1,"b":2,"c":3}
{"a":9,"b":9,"c":3}
$.b | not equal (NUMBER:NUMBER)
2
9
$.a | not equal (NUMBER:NUMBER)
1
9
You fix all the mismatches in one iteration instead of re-running the test for each one. Particularly useful for deeply nested responses. Full reference: Complete Mismatch Diffs.
Soft Assertions
The complement to the per-match diff above: continue execution after a match failure and aggregate failures across multiple steps in a scenario.
* configure continueOnStepFailure = true
* match response.name == 'wrong' # recorded but doesn't stop
* match response.age == 999 # also recorded
* configure continueOnStepFailure = false
Each individual match still emits its complete diff (above) — together you get full failure detail per step and full coverage across the scenario. Full behavior and surface-point rules: configure continueOnStepFailure.
Modern HTTP Client
Apache HttpClient 5.6
Upgraded to Apache HttpClient 5.6 with Brotli compression support and improved connection management.
Declarative Auth
Centralized authentication configuration — no more writing custom karate-config.js headers functions for common auth patterns:
// Basic Auth
configure auth = { type: 'basic', username: 'user', password: 'pass' }
// Bearer Token
configure auth = { type: 'bearer', token: 'your-token' }
// OAuth2 Client Credentials
configure auth = {
type: 'oauth2',
grantType: 'client_credentials',
accessTokenUrl: 'https://auth.example.com/token',
clientId: '...',
clientSecret: '...'
}
// OAuth2 Password Grant
configure auth = {
type: 'oauth2',
grantType: 'password',
accessTokenUrl: 'https://auth.example.com/token',
clientId: '...',
username: '...',
password: '...'
}
// JWT, signed from a payload
configure auth = { type: 'jwt', algorithm: 'HS256', secret: '...', payload: { sub: 'me' } }
// HTTP Digest
configure auth = { type: 'digest', username: '...', password: '...' }
// AWS Signature Version 4
configure auth = { type: 'aws', accessKey: '...', secretKey: '...', region: 'us-east-1', service: 'execute-api' }
// NTLM
configure auth = {
type: 'ntlm',
username: '...',
password: '...',
domain: '...',
workstation: '...'
}
Auth configuration is automatically inherited by called features. Every type and key: Built-in Auth.
Mock Server Rewrite
The mock server has been completely rewritten with the new JS engine and a Netty-based HTTP server for improved performance. See Test Doubles and Mocking for details.
- JavaScript file handlers as an alternative to feature files
- Non-blocking response delays via Netty scheduler
- Built-in CORS support
Gatling Integration
Re-implemented Gatling integration with a pure Java architecture. See Performance Testing for details.
- Java-only DSL (no Scala required)
- PerfHook integration for HTTP-level metrics
- URI pattern matching for request grouping
- Custom performance events for non-HTTP operations
Browser Automation
CDP Driver Rewrite
Complete reimplementation using Chrome DevTools Protocol directly — no WebDriver dependency needed for Chrome/Chromium/Edge.
Auto-wait
Automatic waiting before element operations reduces flaky tests. No more manual waitFor() calls for most interactions.