如何使用脚本在Jmeter容器(如用户参数)中设置变量及其值

编程入门 行业动态 更新时间:2024-10-25 04:18:51
本文介绍了如何使用脚本在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:

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容器(如用户参数)中设置变量及其值

本文发布于:2023-11-11 18:38:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579253.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   变量   容器   脚本   参数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!