且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Jmeter中设置和获取环境变量以测试API

更新时间:2022-02-26 00:10:26

如果您需要获取并设置变量,我建议您使用vars速记

If you need to get and set variables I would recommend using vars shorthand

根据文档

属性与变量不同. 变量是线程本地的;属性是所有线程共有的,需要使用__P或__property函数进行引用.

Properties are not the same as variables. Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function.

因此,我建议将变量设置为:vars.put('foo', 'bar')并以${foo}的形式访问它们,根据我的期望,您将为每个线程(虚拟用户)获得不同的PC_CREATED_PROMO_CODE

So I would suggest setting variables as: vars.put('foo', 'bar') and accessing them as ${foo} where required as my expectation is that you will be getting different PC_CREATED_PROMO_CODE for each thread (virtual user)

另外请注意,还建议您尽可能避免编写脚本,因此请考虑使用

Also be aware that it is also recommended to avoid scripting where possible so consider going for JSON Extractor instead.