Groovy 如何在脚本断言中访问动态值;哪些是在测试用例级别设置的?
我在测试用例级别为下面的响应设置了一个动态值Groovy 如何在脚本断言中访问动态值;哪些是在测试用例级别设置的?,groovy,soapui,Groovy,Soapui,我在测试用例级别为下面的响应设置了一个动态值 { "orderDetails": {"serviceOrderNumber": "SO-EUAM-MX-EUAM-16423"}, "transactionDetails": { "statusMessage": "Success", "startRow": "1", "endRow": "400", "totalRow": "1", "timeZone": "EST"
{
"orderDetails": {"serviceOrderNumber": "SO-EUAM-MX-EUAM-16423"},
"transactionDetails": {
"statusMessage": "Success",
"startRow": "1",
"endRow": "400",
"totalRow": "1",
"timeZone": "EST"
},
"customerNodeDetails": {
"startDate": "20180622 06:32:39",
"nodeCreateDate": "20180622 06:32:39",
"customerId": "5562"
}
}
现在,当断言另一个API是GET-one时,我将
CustID
作为customerNumber
获取
我使用了以下代码:
assert json.customerNodeDetails.customerNumber == "${#TestCase#CustID}"
对同一问题的回答是:
"customerNodeDetails": {
"nodeLabel": null,
"customerNumber": "5544",
"customerName": "ABCDEFGHIJ ABCDEFGHIJ LMNOPQRSTUV1234",
"taxIdCity": "",
"taxIdState": "",
"salesSegment": "Government",
"dunsNumber": "",
"mdsId": "",
"accountClassification": "B",
"specialCustomerBillCode": ""
}.
但我得到的错误如下:
启动失败:Script65.groovy:26:意外字符:“#”@第26行第54列。eDetails.customerNumber==“${{TestCase}^org.codehaus.groovy.syntax.SyntaxException:意外字符:'#'@第26行第54列。位于org.codehaus.groovy.antlr.antlrsparserplugin.transformcstinost(antlrsparserplugin.java:138)
请告诉我如何访问该值。如果您在Groovy脚本中引用属性,则不能像在UI的其他部分中那样直接使用它。您需要扩展它:
def custID = context.expand('${#TestCase#CustID}')
或者,脚本断言中可用的messageExchange
变量为您提供了执行相同操作的替代方法:
def alternative = messageExchange.modelItem.testStep.testCase.getPropertyValue('CustID');
然后,如果您需要在测试用例级别以外的其他地方定义的属性,您可以使用:
def projectLevelProperty = messageExchange.modelItem.testStep.testCase
.testSuite.project.getPropertyValue('projectLevelProperty');
def projectLevelProperty = messageExchange.modelItem.testStep.testCase
.testSuite.project.getPropertyValue('projectLevelProperty');