Karate 在json路径表达式中使用变量
我有一个功能文件,用于从csv文件中检索给定参数的数据。为此,我需要在JsonPath表达式中使用一个变量来检索给定参数的数据。我尝试了多种方法,但在jsonPath中使用变量不起作用。我使用的是0.9.4版本 我尝试了以下方法:Karate 在json路径表达式中使用变量,karate,Karate,我有一个功能文件,用于从csv文件中检索给定参数的数据。为此,我需要在JsonPath表达式中使用一个变量来检索给定参数的数据。我尝试了多种方法,但在jsonPath中使用变量不起作用。我使用的是0.9.4版本 我尝试了以下方法: * def userId = get[0] testData[?(@.UserType=='${userType}')].UserId * def userId = get[0] testData[?(@.UserType==userType)].User
* def userId = get[0] testData[?(@.UserType=='${userType}')].UserId
* def userId = get[0] testData[?(@.UserType==userType)].UserId
* def userId = get[0] testData[?(@.UserType=='#(userType)')].UserId(I suppose this can only be used in json/xml)
以下硬编码值可以正常工作:
* def userId = get[0] testData[?(@.UserType=='SuperAdmin')].UserId
调用的功能:
功能:用于从excel数据源提取各种类型数据的实用程序
背景:
* def DataUtility = Java.type('com.org.utils.DataUtility')
* def dataUtils = new DataUtility()
* def testData = read('classpath:testdata/TestData.csv')
场景:检索给定用户类型的用户ID
* def userId = get[0] testData[?(@.UserType=='${userType}')].UserId
呼叫功能:
* table params
| userType |
| 'SuperAdmin' |
* def extractedData = call read('DataExtractor.feature') params
* def userID = extractedData[0].userId
我尝试过在Json路径中使用变量。 例如: 在这个语句中,i是一个循环变量。在此之后,将其传递到
DocumentContext
的read
api。
这对我来说非常好。
我使用来自jayway的JsonPath和DocumentContext来实现这一点
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
这不是答案。问题是关于[空手道]这里你说的是java
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;