如何使用脚本在Jmeter容器(如用户参数)中设置变量及其值 [英] How to set variable and its value in Jmeter container like User Parameters using script

查看:613
本文介绍了如何使用脚本在Jmeter容器(如用户参数)中设置变量及其值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Jmeter中设置和获取变量以实现API自动化.

I need to set and get variables in Jmeter for API automation.

我正在使用groovy脚本.

I am using the groovy script for same.

我可以使用以下代码在属性文件中存储键值:

I am able to store key-values in Property Files using below code:

props.put("shubhamKey", "shubhamValue")

我不想使用main属性,因为它包含了Jmeter可能使用的许多其他键,因此我们无法将任何硬编码键直接放在属性中.

I do not want to use the main property as it contains so many other keys which may use by Jmeter and we can't place any hardcode key in property directly.

但是我不能在以下任何容器中设置类似的东西:

But I am not an able set similar thing in any of below containers :

  • 用户定义的变量
  • 用户参数

我正在尝试的代码如下:

The code I am trying is as below:

vars.put("shubhamUserKeyagain","shubhamUservalue")

使用vars.put并执行脚本,然后单击用户定义的变量".新密钥应该在那里反映出来,但事实并非如此.这是我的主要问题

Use vars.put and execute the script and click on User Defined Variables. The new key should reflect there but it's not. That is my main issue

我尝试将用户参数放置在TestPlan的下面,在存在JSR223断言的请求中,也尝试将其放置在JSR223断言之前和之后

I have tried to place User Parameters just below in TestPlan, With-in the request where JSR223 Assertion is present, also tried to place it before and after JSR223 Assertion

我的get值在这些容器中工作正常,但该设置未在容器上反映出来.下面的代码,我用来获取值

My get value is working fine from these containers but the set is not reflecting over the containers. Below code, I am using to get the value

vars.get("shubhamLocalVariable")

我尝试过的另一个代码:

Another code I have tried :

vars.putAll("myNormalValue","changeho")

还有其他可以使用脚本作为常规设置和获取键值的容器吗?

Is there any other container in which I can set and get key-values using the script as groovy.

环境:

  • 操作系统:窗口10
  • Jmeter版本:3.2 r1790748
  • 以管理员身份运行bat文件

我已经在下面的URL中添加了我的项目:

I have added my project in below URL:

https://ufile.io/7r6tk

请参考,让我知道是否错过了任何事情

Please refer and let me know if I missed anything

参考屏幕截图:

用户参数

JSR233断言

推荐答案

这一个对我有用-我已经清除了您的脚本

This one works for me - I have cleared up your script

这篇关于如何使用脚本在Jmeter容器(如用户参数)中设置变量及其值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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