使用beanshell更新Jmeter变量 [英] Update Jmeter variables with beanshell

查看:1785
本文介绍了使用beanshell更新Jmeter变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用beanshell脚本更新Jmeter变量时遇到了问题。我已经关注本手册,我看到了这个主题并且都说同样的话:

I've encountered a problem when trying to update a Jmeter variable with a beanshell script. I've followed this manual and i have seen this topic and both say the same:


  1. 要更新变量,请使用 vars.put(variable,newValue);

  2. 你输入的值只能是一个字符串。

现在我想使用这段代码:

Now I want to use this code:

String x = vars.get("counter");

int y = Integer.parseInt(x);
y = y + 1;

String z = "" + y;

vars.put("counter", z);
// print(z);

我的变量计数器是一个用户参数(在用户定义的变量之前尝试过),其值为1.我可以看到我的脚本正在运行,因为print(z)返回值2.现在我还说明我的变量计数器在用户参数中更新,这样当我再次运行它时它给我的值为3.这不是这种情况:该值未更新,因此每次运行脚本时它都会返回值2。

My variable counter is a user parameter (tried before as user defined variable) with the value 1. I can see my script is working because the print(z) returns the value 2. Now I also expact that my variable counter is updated in the user parameters so that when I run this again it gives me the value 3. This is not the case: The value is not updated, so everythime I run the script it returns me the value 2.

任何可以帮助我的人?

Anyone who can help me with this?

推荐答案

我的脚本中没有任何问题。它应该可以正常工作。

I do not see any issues in your script. It should work fine.

请记住,所有这些beanhell变量都是特定于线程的。即,如果Thread1将其递增为2,则Thread2的'counter'的当前值仍将为1.

Remember that all these beanshell variables are specific to the thread. Ie, If Thread1 increments it to 2, the current value of 'counter' for the Thread2 will still be 1.

我认为您为更多线程/用户运行测试只有一次迭代。这就是为所有用户打印2的原因。如果你有更多的循环计数/将它设置为永久,计数器将增加。

I think you run your test for more threads/users with only one iteration. This is why it prints 2 for all users. If you have more loop counts/set it to forever, counter will get incremented.

如果jmx文件仍然无法解决问题,你可以上传它。

You can upload your jmx file if it still does not resolve the issue.

编辑:

我刚查过你的jmeter测试。即使您在Beanshell Sampler中将计数器值增加1,Yolu也会将计数器设置为1,作为用户参数的一部分。去掉它。删除后,它对我来说很好。

I just checked your jmeter test. Even though you increment the counter value by 1 in the Beanshell Sampler, Yolu are setting the counter back to 1 as part of User Parameters. Remove it. After removing them, It works fine for me.

这篇关于使用beanshell更新Jmeter变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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