我试图在JSR223 Groovy Assertion中设置从Jmeter属性中提取的Jmeter变量。
我感兴趣的Jmeter属性如下:
... created_blob_A_6= fde65de0-3e32-11e8-a5b4-3906549016d8 created_blob_A_8= fef92d70-3e32-11e8-a5b4-3906549016d8 created_blob_A_9= ff775e20-3e32-11e8-bac3-e51250ffea15 created_blob_B_1= fd7302a0-3e32-11e8-a5b4-3906549016d8 created_blob_B_10= 00141350-3e33-11e8-bac3-e51250ffea15 ...
为了从Jmeter属性中提取值,我已经为JSR223 Groovy创建了以下断言脚本:
def readParamPrefix = 'created_blob'
def writeParamPrefix = 'blob_to_delete'
def chucnkTypes = 'A'..'E'
def newBlobCounter = 1
chucnkTypes.each{ chunkLetter ->
(1..10).each{ streamNumber ->
String readParamName = readParamPrefix + '_' + chunkLetter + '_' + streamNumber
log.info('Read param name: ' + readParamName)
String writeParamName = writeParamPrefix + '_' + newBlobCounter
log.info('Write param name: ' + writeParamName)
String blob_id_to_delete = props.get(readParamName).toString().trim()
log.info('' + readParamName + ' => ' + writeParamName + ' (' + blob_id_to_delete + ')')
vars.put(writeParamName.toString(), blob_id_to_delete.toString())
newBlobCounter++
}
}
该脚本不适用于JMeter变量,但适用于JMeter属性。以下是JMeter的特色:
JMeterProperties: ... blob_to_delete_1=9b1c4f40-3e36-11e8-a5b4-3906549016d8 blob_to_delete_10=9da5e050-3e36-11e8-bac3-e51250ffea15 blob_to_delete_11=9b235420-3e36-11e8-bac3-e51250ffea15 blob_to_delete_50=9b656630-3e36-11e8-bac3-e51250ffea15
您能告诉我,如何正确修改我的代码以正确设置JMeter变量?
答案 0 :(得分:0)
请勿在脚本中使用$ {varName},请注意JSR223 Best Practices:
确保脚本不使用$ {varName}的任何变量,因为缓存只会获取$ {varName}的第一个值。而是使用: vars.get( “varName中”) 您也可以将它们作为参数传递给脚本并以这种方式使用它们。
更改后,如果日志仍无法正常工作,请在日志中查找错误
答案 1 :(得分:0)
我认为您的代码没有任何问题:
所以我建议: