admin管理员组文章数量:1292879
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;
}
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.
Edit: 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);
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;
}
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.
Edit: 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);
Share
Improve this question
edited Feb 13, 2013 at 12:24
Aliaksandr Belik
12.9k6 gold badges68 silver badges92 bronze badges
asked Feb 13, 2013 at 11:32
Ruchit RamiRuchit Rami
2,2824 gold badges29 silver badges53 bronze badges
3 Answers
Reset to default 5You 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.
You should WebDriver plugin for that. It can be configured as IE/Firefox/Chrome or even Selenium.
The documentation here
This is how you configure IE web driver
For anyone reading this years later:
Calling javascript function is possible from a BSF PostProcessor.
You need to define your function higher up in the file than where it is used.
This means this works:
function decode(str) {
(...... do stuff......)
return something;
}
var bar = decode("foo");
vars.put("someVariableName", bar);
However this doesn't work:
var bar = decode("foo"); // <--- Compile error, undefined function 'decode'
vars.put("someVariableName", bar);
function decode(str) {
(...... do stuff......)
return something;
}
本文标签: Adding javascript function to jMeterStack Overflow
版权声明:本文标题:Adding javascript function to jMeter - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741565544a2385699.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论