JMeter在HTTP请求中使用beanshell变量 [英] JMeter use beanshell variable in HTTP Request

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

问题描述

我在这里绝对是个菜鸟(我是说JAVA),花了数小时寻找解决方案,现在我只想开枪自杀.
我想在放置在HTTP请求上方的beanshell断言中创建一个字符串.

I'm an absolute rookie here (JAVA i mean), spent hours looking for a solution, now i just want to shoot myself.
I want to create a string in the beanshell assertion which is placed right above the HTTP Request.

  • 我在beanshell中写道:

  • In the beanshell i wrote:

String docid="abcd";

(实际上,我希望将一个字符串与一些变量连接起来)

(in actuality i wish to concatenate a string with some variables)

在HTTP请求中,发送参数我添加${docid}.

In HTTP Request, send parameters i add ${docid}.

推荐答案

BeanShell断言描述部分中您可以找到以下内容:

In BeanShell Assertion description section you can find the following:

 vars -  JMeterVariables  - e.g. vars.get("VAR1"); vars.put("VAR2","value"); vars.putObject("OBJ1",new Object()); 
 props - JMeterProperties (class java.util.Properties) - e.g. props.get("START.HMS"); props.put("PROP1","1234");

因此要在beanshell代码(您的情况下为BeanShell断言采样器)中设置jmeter变量,请使用以下命令:

So to set jmeter variable in beanshell code (BeanShell Assertion sampler in your case) use the following:

String docid = "abcd";
vars.put("docid",docid);

或者简单地

vars.put("docid","abcd");

,然后您可以将其称为$ {docid},就像在HTTP请求中所做的一样.

and then you can refer it as ${docid}, as you've done in your HTTP Request.

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

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