[英]Adding javascript function to jMeter using jsr223
I am trying to get a javascript function work with jMeter test plan uing JSR223. 我正在尝试使用JSR223将jMeter测试计划与javascript函数一起使用。 It is used to decode a string.
它用于解码字符串。 I have the below two functions which i need to implement in jmeter:
我有以下两个功能需要在jmeter中实现:
function AESEncryption(text, passphase, bytessize) {
var key = CryptoJS.enc.Utf8.parse('ABCDEFGHIJKL1234567891234');
var iv = CryptoJS.enc.Utf8.parse('1234567890123456');
var blocksize = bytessize / 2;
var encrypted = CryptoJS.AES.encrypt(CryptoJS.enc.Utf8.parse(text), passphase, key,
{
keySize: bytessize,
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
var dta = String(encrypted);
return dta;}
function AESDecryption(text, key, bytessize) {
try {
//alert(text + ":" + key + ":" + bytessize);
var e = CryptoJS.AES.decrypt(text, key, bytessize);
//alert("Ec:" + e);
return CryptoJS.AES.decrypt(text, key, bytessize).toString(CryptoJS.enc.Utf8);
}
catch (Error) {
return "";}}
You can import external JavaScript into JSR223 Sampler using load
directive. 您可以使用
load
指令将外部JavaScript导入JSR223 Sampler。
Add the next line to the beginning of your JSR223 script: 将下一行添加到JSR223脚本的开头:
load('crypto-js-3.1.9/crypto-js.js');
You should be able to access your JavaScript functions directly in the JSR223 Sampler 您应该能够直接在JSR223 Sampler中访问JavaScript函数。
Be aware that JavaScript being interpreted via Rhino/Nashorn has serious performance drawbacks therefore if you are planning to call this funciton by many threads it makes more sense to rewrite your functions in Groovy . 请注意,通过Rhino / Nashorn解释的JavaScript具有严重的性能缺陷,因此,如果您打算通过许多线程调用此函数,则在Groovy中重写函数会更有意义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.