jmeter beanshell 变量传递
如果写成这样会报错:
${__BeanShell(${__threadNum}*2,ToatlAmount)};
${__BeanShell(${__Random(1,99999,)},DayNum)};
//${__BeanShell(vars.put("BXReason"\,"${__UUID}"))};
${__BeanShell(${__threadNum},BXReason)};
报错信息:
2018-12-20 01:42:30,820 ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``StandardJMeterEngine*2;'' : illegal use of undefined variable, class, or 'void' literal
2018-12-20 01:42:30,820 WARN o.a.j.f.BeanShell: Error running BSH script
org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``StandardJMeterEngine*2;'' : illegal use of undefined variable, class, or 'void' literal
at org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:183) ~[ApacheJMeter_core.jar:5.0 r1840935]
at org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:189) ~[ApacheJMeter_core.jar:5.0 r1840935]
at org.apache.jmeter.functions.BeanShell.execute(BeanShell.java:100) [ApacheJMeter_functions.jar:5.0 r1840935]
at org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:136) [ApacheJMeter_core.jar:5.0 r1840935]
at org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:111) [ApacheJMeter_core.jar:5.0 r1840935]
at org.apache.jmeter.testelement.property.FunctionProperty.getStringValue(FunctionProperty.java:92) [ApacheJMeter_core.jar:5.0 r1840935]
at org.apache.jmeter.testbeans.TestBeanHelper.unwrapProperty(TestBeanHelper.java:128) [ApacheJMeter_core.jar:5.0 r1840935]
at org.apache.jmeter.testbeans.TestBeanHelper.prepare(TestBeanHelper.java:83) [ApacheJMeter_core.jar:5.0 r1840935]
at org.apache.jmeter.engine.StandardJMeterEngine.notifyTestListenersOfStart(StandardJMeterEngine.java:212) [ApacheJMeter_core.jar:5.0 r1840935]
at org.apache.jmeter.engine.StandardJMeterEngine.run(StandardJMeterEngine.java:384) [ApacheJMeter_core.jar:5.0 r1840935]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_172]
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_172]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_172]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_172]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_172]
at org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:166) ~[ApacheJMeter_core.jar:5.0 r1840935]
... 10 more
import java.text.DecimalFormat;
String a0=props.get("newtoken");
vars.put("token2",a0);
String a0=props.get("newcompanyId");
vars.put("companyId2",a0);
String a2=props.get("newuserId");
vars.put("userId2",a2);
String a3=props.get("newuserName");
vars.put("userName2",a3);
String a4=props.get("neworgCode");
vars.put("orgCode2",a4);
String a5=props.get("newcostCenterName");
vars.put("costCenterName2",a5);
String a6=props.get("newprofitCenterName");
vars.put("profitCenterName2",a6);
String a7=props.get("newcostCenterID");
vars.put("costCenterID2",a7);
String ToatlAmount="${__BeanShell(${__threadNum}*2,)}";
vars.put("ToatlAmount",ToatlAmount);
String DayNum="${__Random(1,99999,)}";
vars.put("DayNum",DayNum);
String BXReason="${__threadNum}";
vars.put("BXReason",BXReason);

4、Bean Shell常用内置变量
JMeter在它的BeanShell中内置了变量,用户可以通过这些变量与JMeter进行交互,其中主要的变量及其使用方法如下:
log:用来记录日志文件,写入到jmeber.log文件,使用方法:log.info(“This is log info!”);
ctx(JmeterContext)通过它来访问context,使用方法可参考:org.apache.jmeter.threads.JMeterContext。
vars - (JMeterVariables):操作jmeter变量,提供读取/写入访问变量的方法。这个变量实际引用了JMeter线程中的局部变量容器(本质上是Map),它是测试用例与BeanShell交互的桥梁,常用方法:
a) vars.get(String key):从jmeter中获得变量值
b) vars.put(String key,String value):数据存到jmeter变量中
c) vars.putObject("OBJ1",new Object());
更多方法可参考:org.apache.jmeter.threads.JMeterVariables
props - (JMeterProperties - class Java.util.Properties):操作jmeter属性,该变量引用了JMeter的配置信息,可以获取Jmeter的属性,它的使用方法与vars类似,但是只能put进去String类型的值,而不能是一个对象。对应于java.util.Properties。
a) props.get("START.HMS"); 注:START.HMS为属性名,在文件jmeter.properties中定义
b) props.put("PROP1","1234");
prev - (SampleResult):获取前面的sample采样的结果,常用方法:
a) getResponseDataAsString():获取响应信息
b) getResponseCode() :获取响应code
更多方法可参考:org.apache.jmeter.samplers.SampleResult
sampler - (Sampler):gives access to the current sampler 访问当前采样
BeanShell PostProcessor脚本:
String newtoken=bsh.args[0];
print(newtoken);
${__setProperty(newtoken,${token},)};
String newcompanyId=bsh.args[1];
print(newcompanyId);
${__setProperty(newcompanyId,${companyId},)};
String newuserId=bsh.args[2];
print(newuserId);
${__setProperty(newuserId,${userId},)};
String newuserName=bsh.args[3];
print(newuserName);
${__setProperty(newuserName,${userName},)};
String neworgCode=bsh.args[4];
print(neworgCode);
${__setProperty(neworgCode,${orgCode},)};
String newcostCenterName=bsh.args[5];
print(newcostCenterName);
${__setProperty(newcostCenterName,${costCenterName},)};
String newprofitCenterName=bsh.args[6];
print(newprofitCenterName);
${__setProperty(newprofitCenterName,${profitCenterName},)};
String newcostCenterID=bsh.args[7];
print(newcostCenterID);
${__setProperty(newcostCenterID,${costCenterID},)};

jmeter beanshell 变量传递的更多相关文章
- jmeter 之变量传递
最近遇到个问题,一个线程组的变量怎么应用到另一个线程组,试了下,通过提取器设置的变量只能用于当前线程组,不能用于其他线程组,只能试试设置property Parameters,应该还有别的办法这只是其 ...
- jmeter BeanShell实例-----两个变量之间的断言对比
jmeter BeanShell实例-----两个变量之间的断言对比 在jmeter的中,断言没法对两个变量的进行对比后判断,只能使用Bean Shell断言来进行,总是有人来问怎么写呢.这里写一个简 ...
- jmeter BeanShell实例-----两个变量之间的断言对比(转)
jmeter BeanShell实例-----两个变量之间的断言对比 在jmeter的中,断言没法对两个变量的进行对比后判断,只能使用Bean Shell断言来进行,总是有人来问怎么写呢.这里写一个简 ...
- Jmeter之BeanShell变量使用讲解
一.在测试过程中经常会遇到一些业务逻辑处理需要,单纯的线程设置不能满足,这时候就要使用BeanShell编写一定的脚本 前置处理器:BeanShell PreProcessor,主要接口请求前做一些参 ...
- jmeter BeanShell断言(一)
原文地址https://blog.csdn.net/lijing742180/article/details/81157947 原文地址https://blog.csdn.net/zailushang ...
- JMeter BeanShell示例
翻译:https://blog.trigent.com/jmeter-blog-series-jmeter-beanshell-example 在这个例子中,我们将演示在Apache JMeter中使 ...
- JMeter博客系列:JMeter BeanShell示例
1.简介 Apache JMeter是一个基于Java的开源工具,使您可以在应用程序上执行功能,负载,性能和回归测试.应用程序可以在Web服务器上运行,也可以是独立的.它支持在包含静态和动态资源的客户 ...
- Jmeter Beanshell 编程简介
简介 Jmeter除了提供丰富的组件以外,还提供脚本支持,可通过编写脚本来丰富Jmeter,实现普通组件无法完成的功能.Beanshell是一种轻量级的Java脚本语言,完全符合Java规范,并且内置 ...
- Jmeter beanshell 生成手机号加密签名
首先自己写一个根据手机号生成加密字符串的函数,并且导出为Jar包,函数具体内容省略,网上有很多 将Jar包放到Jmeter lib\ext目录下面,然后在user.properties里面把路径加进去 ...
随机推荐
- Robot Framework 执行结果无法查看(tomcat部署)
打开jenkins系统管理-命令行执行: System.setProperty("hudson.model.DirectoryBrowserSupport.CSP","& ...
- [fw]PAGE_SIZE & PAGE_SHIFT & _AC()
PAGE_SIZE & PAGE_SHIFT & _AC() 在大多系统下,PAGE_SIZE被定义为 4k 大小,即 4096 字节. 在 x86 系统里,PAGE_SIZE 和 P ...
- sublime text 3安装Anaconda插件之后写python出现白框
sublime test 3安装anaconda插件之后写python代码会出现白框,这是应为anaconda自带了pep8语法检查, 有一些是语法错误,能够检查出来还是能有用的.但有一些不过是一些代 ...
- Java compiler level does not match the version of the installed Java project facet错误
出现问题情景:从其他地方导入一个项目的时候报错:Java compiler level does not match the version of the installed Java project ...
- Linux 下安装sql server 时 2G内存限制的最新(2019-08-15) 解决方案
关于 sqlserver 在linux下安装时有最小内存限制的问题,网上有很多类似的说明,那些操作都是正确的,如果不成功可能 “姿势”不对. 需要注意的是:不能使用最新版本!!! 不能在线下载!!! ...
- react 编写 基于ant.design 页面的参考笔记
前言 因为我没有系统的学习 react,是边写边通过搜索引擎找相对的问题,看 ant.design的 中文文档 编写的一个单页面, 以下的笔记都是写 gksvideourlr 时记录的. 重新设定表单 ...
- 配置框架spring和SpringDataJpa整合----员工是爹
<!-- 1.dataSource 配置数据库连接池--> <bean id="dataSource" class="com.mchange.v2.c3 ...
- python--生成器、三元表达式、列表解析、生成器表达式
补充: 在文件开头声明一个空字典,然后在每个函数前加上装饰器,完成自动添加到字典的操作 func_dic={} def make_dic(key): def deco(func): func_dic[ ...
- php floor()函数 语法
php floor()函数 语法 floor函数是什么意思? php floor()函数用来向下舍入为最接近的整数.语法是floor(number),表示返回不大于参数number的下一个整数,有小数 ...
- Linux系统之-常用命令及技巧
一. 通用命令:1.date :print or set the system date and time2. stty -a: 可以查看或者打印控制字符(Ctrl-C, Ctrl-D, Ctrl-Z ...