向jMeter添加javascript函数 [英] Adding javascript function to jMeter
问题描述
我正在尝试使JavaScript功能与jMeter测试计划一起使用.
用于解码字符串.
I am trying to get a javascript function work with jMeter test plan.
It is used to decode a string.
function decode(str) {
var strtodecrypt = str.split("-");
var msglength = strtodecrypt.length;
decrypted_message = "";
for (var position = 0; position < msglength; position++) {
ascii_num_byte_to_decrypt = strtodecrypt[position];
ascii_num_byte_to_decrypt = ascii_num_byte_to_decrypt / 2;
ascii_num_byte_to_decrypt = ascii_num_byte_to_decrypt - 5;
decrypted_byte = String.fromCharCode(ascii_num_byte_to_decrypt);
decrypted_message += decrypted_byte;
}
return decrypted_message;
}
我尝试使用BSF Post处理器,但是不知道我需要使用的确切语法是什么.我想使用此函数在一个HTTP请求中将jMeter变量作为参数发布.
I have tried to use BSF Post processor, but don't know what is the exact syntax i need to use. I want to use this function to post a jMeter variable as a parameter in one of the HTTP request.
编辑:我当前在BSF后处理器中使用以下脚本. userResponse
不显示在debub采样器中.我需要添加任何引用以使用String.fromCharCode(ascii_num_byte_to_decrypt)
吗?
I am currently using following script in the BSF post processor. userResponse
does not show in debub sampler. Do i need to add any reference to use String.fromCharCode(ascii_num_byte_to_decrypt)
?
var str="142";
var strtodecrypt = str.split("-");
var msglength = strtodecrypt.length;
decrypted_message = "";
for (var position = 0; position < msglength; position++) {
ascii_num_byte_to_decrypt = strtodecrypt[position];
ascii_num_byte_to_decrypt = ascii_num_byte_to_decrypt / 2;
ascii_num_byte_to_decrypt = ascii_num_byte_to_decrypt - 5;
decrypted_byte = String.fromCharCode(ascii_num_byte_to_decrypt);
decrypted_message += decrypted_byte;
}
vars.put("userResponse",decrypted_message);
推荐答案
You can try to use as well JSR223 Sampler with script language set to javascript (Language: JavaScript
).
It will process your script (2nd version), variable set and available in debug Sampler results.
这篇关于向jMeter添加javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!