大家好!
我在JMeter JSR223中遇到Groovy ReplaceAll的问题。在一种情况下,它可以工作,在另一种情况下,它不能工作。
已经尝试过并尝试了Sampler和Preprocessor。但是什么都没有改变。
Jmeter 5.1.1 JSR223采样器和JSR223预处理器
--------------工作-----------------
import "core-js/stable";
import "regenerator-runtime/runtime";
def bodyData_3DS_default = '' +
'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
'<soap:Body>' +
'<ns3:sendSms xmlns:ns2="" xmlns:ns3="">' +
'<customerId>' + '$' + '{customerId}' + '</customerId>' +
'<customerType>' + '$' + '{customerType}' + '</customerType>' +
'<phone>' + '$' + '{phone}' + '</phone>' +
'<templateId>' + '$' + '{templateId}' + '</templateId>' +
'<!--Optional:-->' +
'<smsFlag>' + '$' + '{smsFlag}' + '</smsFlag>' +
'<callingSystemName>' + '$' + '{callingSystemName}' + '</callingSystemName>' +
'</ns3:sendSms>' +
'</soap:Body>' +
'</soap:Envelope>';
bodyData_3DS_default = bodyData_3DS_default.replaceAll('<!--[A-Za-z_0-9:<>${}/ ]*-->', '');
vars.put('bodyData_3DS_default', bodyData_3DS_default);
--------------结果----------------
def bodyData = '${bodyData_3DS_default}';
['smsFlag'].each { removeOptional ->
bodyData = bodyData.replaceAll('<'+ "${removeOptional}" + '[A-Za-z_0-9:<>${}()/_]*' + "</${removeOptional}" + '>', '');
}
vars.put('bodyData', bodyData);
------------不工作---------------------------
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns3:sendSms xmlns:ns2="" xmlns:ns3=""><customerId>CUSTOM</customerId><customerType>PHYSICAL</customerType><phone>79990001122</phone><templateId>000000006</templateId><callingSystemName>acs</callingSystemName></ns3:sendSms></soap:Body></soap:Envelope>
def bodyData_Services_default = '' +
'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
'<soap:Body>' +
'<ns3:sendSms xmlns:ns2="" xmlns:ns3="">' +
'<customerId>' + '$' + '{customerId}' + '</customerId>' +
'<customerType>' + '$' + '{customerType}' + '</customerType>' +
'<phoneAlgorithm>' + '$' + '{phoneAlgorithm}' + '</phoneAlgorithm>' +
'<text>' + '$' + '{textSms}' + '</text>' +
'<!--Optional:-->' +
'<smsFlag>' + '$' + '{smsFlag}' + '</smsFlag>' +
'<callingSystemName>' + '$' + '{callingSystemName}' + '</callingSystemName>' +
'</ns3:sendSms>' +
'</soap:Body>' +
'</soap:Envelope>';
bodyData_Services_default = bodyData_Services_default.replaceAll('<!--[A-Za-z_0-9:<>${}/ ]*-->', '');
vars.put('bodyData_Services_default', bodyData_Services_default);
---------结果------------------------------
def bodyData = '${bodyData_Services_default}';
['smsFlag'].each { removeOptional ->
bodyData = bodyData.replaceAll('<'+ "${removeOptional}" + '[A-Za-z_0-9:<>${}()/_ ]*' + "</${removeOptional}" + '>', '');
}
vars.put('bodyData', bodyData);