BeanShell PreProcessor更新用户定义变量 [英] BeanShell PreProcessor updates User define variables

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

问题描述

我是JMeter的新手.

I'm very new at JMeter issues.

在测试脚本中,我有一个BeanShell PreProcessor元素,该元素可更新以前在用户定义的变量"元素上定义的一些变量.

In a test script i have a BeanShell PreProcessor element that updates some variables previously defined at a "User Defined Variables" element.

后来,这些变量在"Http请求"中使用.但是,http请求中使用的值是默认值.

Latter those variables are used in "Http Requests". However, the value that is used in the http request is the default one.

由于进行了一些调试print(),这些脚本似乎可以正常工作

The scripts seems to be working due to some debug print();

我的问题是是否有必要延迟脚本以确保BeanShell完成?

My question is if it's necessary to delay the script to be sure that the BeanShell finishes?

非常感谢您的关注

推荐答案

由于请求之前被执行,因此无需对Beanshell Pre-Processor进行任何延迟.我建议检查您的 jmeter.log 文件以查看是否存在脚本问题,因为Beanshell Pre-Processor不会在任何地方报告错误,包括查看结果树"侦听器.

There is no need to put any delay to Beanshell Pre-Processor as it's being executed before request. I'd recommend to check your jmeter.log file to see if there are any scripting issues as Beanshell Pre-Processor does not report errors anywhere including View Results Tree listener.

至少有两种方法可以确保您的Beanshell脚本一切正常:

There are at least 2 ways to assure that everything is fine with your Beanshell script:

  1. 在变量替换逻辑以之后放置调试打印代码,以查看是否触发
  2. 在您的HTTP请求中直接使用JMeter __Beahshell 函数.如果可以的话-查看结果树将演示beanshell生成的值.如果不是,则该字段将为空白,并且相关错误将显示在日志中.
  1. Put your debug print code after variables replace logic to see if it fires
  2. Use JMeter __Beahshell function right in your HTTP request. If it's ok - View Results Tree will demonstrate beanshell-generated value. If not - the field will be blank and relevant error will be displayed in the log.

示例测试用例:

给出以下测试计划结构:

Given following Test Plan structure:

  • 具有1个用户和1个循环的线程组
  • 对google.com的HTTP GET请求,其中包含/的路径和参数q

如果您提供以下beanshell函数作为参数"q":

If you provide as parameter "q" following beanshell function:

${__BeanShell(System.currentTimeMillis())}

并查看查看结果树"的请求"标签,您应该会看到类似以下内容的

and look into View Results Tree "Request" tab you should see something like:

GET http://www.google.com/?q=1385206045832

,如果您将功能更改为不正确的内容,例如:

and if you change function to something incorrect like:

${__BeanShell(Something.incorrect())}

您将看到一个空白请求.

you'll see a blank request.

更改现有变量(如果不存在变量,则创建新变量)的正确方法如下

The correct way of changing existing variable (or creating new if variable doesn't exist) looks like

vars.put("variablename", "variablevalue");

* 重要信息:* JMeter变量是Java字符串,如果要为JMeter变量设置其他内容(日期,整数等),则需要以某种方式将其转换为String.

*Important: * JMeter Variables are Java Strings, if you're trying to set something else (date, integer, whatever) to JMeter Variable you need to cast it to String somehow.

示例:

int i = 5;
vars.put("int_i", String.valueOf(i));

希望这会有所帮助.

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

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