如何在Jmeter中加载外部js库? [英] How to load external js library in Jmeter?

查看:1782
本文介绍了如何在Jmeter中加载外部js库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jsr223采样器中有以下代码:

I have the following code in a jsr223 sampler:

var key = "key";
var dateStamp = "20160329T134359Z";
var regionName = "us-east-1";
var serviceName = "execute-api";

   var kDate= Crypto.HMAC(Crypto.SHA256, dateStamp, "AWS4" + key, { asBytes: true})
   var kRegion= Crypto.HMAC(Crypto.SHA256, regionName, kDate, { asBytes: true });
   var kService=Crypto.HMAC(Crypto.SHA256, serviceName, kRegion, { asBytes: true });
   var kSigning= Crypto.HMAC(Crypto.SHA256, "aws4_request", kService, { asBytes: true });
   vars.put("AWSKey", kSigning);

现在当我运行它时出现此错误:
回复代码:500
响应消息:javax.script.ScriptException:sun.org.mozilla.javascript.internal.EcmaError:ReferenceError:未定义加密。 (#6)在第6行

Now when I run it i get this error: Response code: 500 Response message: javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "Crypto" is not defined. (#6) in at line number 6

显然我没有加密库。但是我对如何装载它们感到茫然。我下载了所有的相关js并将它们放在/ lib文件夹中,但仍然没有。
我下载了这个文件: https://github.com/Boussetta/CryptoJS-v3。 1.2
哪个处理上面代码中的功能但是对于我的生活我不知道如何导入它。

Obviously I dont have the crypto libs. However I am at loss on how to load them. I downloaded all the relavant js and put them in the /lib folder and still nothing. I downloaded this file: https://github.com/Boussetta/CryptoJS-v3.1.2 Which handles the functions in the code above but for the life of me I have not idea how to import it.

TIA

推荐答案

如果您想使用JavaScript - 有两种选择:

If you want to go for JavaScript - there are 2 options:


  1. 使用Rhino load()方法如:

load(crypto.js)

使用 HmacUtils 类。来自JavaScript的org / proper / commons-codec /rel =nofollow> Apache Commons Codec

Use HmacUtils class from Apache Commons Codec from JavaScript

var rawhmac = org.apache.commons.codec.digest.HmacUtils.hmacSha1(key,data)
var encoded = org.apache.commons.codec.binary.Base64.encodeBase64String(rawhmac)


但是我建议选择3 - 切换到groovy语言JavaScript的方式,你将能够:

However I would recommend going for option 3 - switch to "groovy" language instead of JavaScript, that way you will be able to:

  • Re-use Amazon authentication samples in your test
  • Get maximum performance and confidence as groovy scripts can be compiled while other languages are interpreted so groovy implementation will take less resources and will work faster. See Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! article for more details.

这篇关于如何在Jmeter中加载外部js库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆