将 javascript 函数添加到 jMeter

Ruc*_*ami 3 javascript jmeter

我正在尝试使用 jMeter 测试计划获得一个 javascript 函数。
它用于解码字符串。

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;
}
Run Code Online (Sandbox Code Playgroud)

我曾尝试使用 BSF 后处理器,但不知道我需要使用的确切语法是什么。我想使用此函数在 HTTP 请求之一中将 jMeter 变量作为参数发布。

编辑: 我目前在 BSF 后处理器中使用以下脚本。userResponse不显示在 debub 采样器中。我需要添加任何引用才能使用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);
Run Code Online (Sandbox Code Playgroud)

Ali*_*lik 5

您也可以尝试使用脚本语言设置为 javascript ( ) 的JSR223 SamplerLanguage: JavaScript
它将处理您的脚本(第二版)、变量集并在调试采样器结果中可用。