我无法在groovy中评估以下语句:
def responseAct = new JsonSlurper().parseText(testRunner.testCase.getTestStepByName(Step).getPropertyValue("response"));
String x = "response.errorNumber";
String evaluate = "def value = responseAct." + x;
Eval.me(evaluate);
我得到的错误是:
groovy.lang.MissingPropertyException
答案 0 :(得分:0)
应该是:
def responseAct = [
response: [
errorNumber: 2
]
]
String x = "response.errorNumber";
String evaluate = "def value = $responseAct." + x
Eval.x(responseAct, evaluate)
答案 1 :(得分:0)
@Opal,是的......解决了这个问题。它只是JSON数据的变量应该是JsonSlurper的一个对象。这是一个有效的例子:
def objResponse = new JsonSlurper().parseText(testRunner.testCase.getTestStepByName("Step Name for Rest Step").getPropertyValue("response"));
String res = "response.errorNumber";
String evaluate = "x." + res;
String value = Eval.x(objResponse, evaluate);