问题
When i am passing the value of a string json filter is working fine. But when I am passing embedded expression in the JSONPATH it is not replacing actual value.
Given url appServer +'/integration/rest/user'+'?page=0'+'&pageSize=10'+'&fieldList=first_name,last_name,id,username,last_login,active,date_created'+'&filter=user_type%20equals%20%27P%27%20'+'&getTotalRecordCount=true'
And header X-CSRF-TOKEN = csrfToken * cookie JSESSIONID = jsessionid * print routevalue * cookie route = routevalue * string searchUser = 'anupama'
* callonce sleep 10
Given request ' '
When method get Then status 200 * def usernames = get response.integration.serviceData.record[*].username * print usernames * print searchUser * def userNode = get[0] response.integration.serviceData.record[?(@.username== '#(searchUser)')] * print userNode
回答1:
Embedded expressions are only for JSONPath and XML: https://github.com/intuit/karate#embedded-expressions
Please use the karate
API for dynamic JsonPath: https://github.com/intuit/karate#jsonpath-filters
* def userNode = karate.jsonPath(response, "$.integration.serviceData.record[?(@.username=='" + searchUser + "')]")
来源:https://stackoverflow.com/questions/52218765/embedded-expressions-are-not-replaced-in-the-jsonpath-filter