Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
877 views
in Technique[技术] by (71.8m points)

karate - Embedded expressions are not replaced in the JSONPATH filter

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 userNodeenter image description here

question from:https://stackoverflow.com/questions/65895933/karate-replace-variables-in-text-type

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 + "')]")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...