Description
In Karate v2, match $.field == '#notpresent' throws No results for path: $['field'] when the field doesn't exist in the response. In v1, this correctly passed — asserting the field is absent.
It seems like the issue is specifically with $ JsonPath syntax. Dot-notation (response.field) works correctly with #notpresent.
Steps to Reproduce
- Create a feature file using the snippets below.
Feature: match $.field == '#notpresent' throws error when field doesn't exist (v2 regression)
# Bug: $ JsonPath syntax throws "No results for path" on missing fields,
# breaking #notpresent assertions. Dot-notation works as workaround.
Scenario: $ JsonPath - existing field works, missing field breaks #notpresent
Given url 'https://httpbin.org'
And path '/anything'
And request { name: 'test', value: 123 }
When method post
Then status 200
# PASSES: existing field with $ syntax
* match $.method == 'POST'
# FAILS in v2: "No results for path: $['errors']"
# PASSES in v1: correctly asserts field is absent
* match $.errors == '#notpresent'
Scenario: response dot-notation - workaround that works in both v1 and v2
Given url 'https://httpbin.org'
And path '/anything'
And request { name: 'test', value: 123 }
When method post
Then status 200
# PASSES in both v1 and v2
* match response.method == 'POST'
* match response.errors == '#notpresent'
Expected Behavior
- The scenario should pass, matching the v1 behavior.
Actual Behavior
- Scenario fails with $ JsonPath syntax when the field is not present.
Karate Version
2.0.9
Java Version
25.0.2
Operating System
macOS
Description
In Karate v2,
match $.field == '#notpresent'throws No results for path: $['field'] when the field doesn't exist in the response. In v1, this correctly passed — asserting the field is absent.It seems like the issue is specifically with $ JsonPath syntax. Dot-notation (response.field) works correctly with #notpresent.
Steps to Reproduce
Expected Behavior
Actual Behavior
Karate Version
2.0.9
Java Version
25.0.2
Operating System
macOS