如何从Jmeter中的请求中提取值 [英] how to extract value from request in Jmeter

查看:363
本文介绍了如何从Jmeter中的请求中提取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在传递一封电子邮件,该电子邮件具有以下功能

Hi I am passing an email which is a time function like below

email = ${__time(MMddyy)}_${__time(HMS)}@yopmail.com

此函数的值更改eveytime,我称此变量为email. 我想将此函数生成的值存储到变量中,并在其他请求中使用.

The value of this function changes eveytime I call the variable email. I would like to store this value that is generated from this function into a variable and use that in other requests.

因此,由于两个http请求之间存在一定的时间间隔,因此当前我在两个不同的http请求中收到了两个不同的电子邮件.

So currently I am getting two different emails in two different http requests since there is some time lag between my two http requests.

我想做的是..通过从请求中提取值并将其传递到第二个HTTP请求中来存储正在第一个HTTP请求中发送的电子邮件.

what I would like to do is .. store the email that is being sent in first http request by extracting the value from the request and pass it in the second http request.

POST data:
email=062915_160738%40yopmail.com

我知道从html响应中提取的方法..但是有什么方法可以从jmeter中的请求中提取吗?

I know the way to extract from html response.. but is there any way to extract from request in jmeter?

如果可以的话,有人可以告诉我如何实现这一目标吗?

If so can someone pls tell me how to achieve this?

谢谢

推荐答案

  1. 添加一个Beanshell PostProcessor作为发送该POST请求的请求的子代
  2. 将以下代码放入PostProcessor的脚本"区域

  1. Add a Beanshell PostProcessor as a child of the request which sends that POST request
  2. Put the following code into the PostProcessor's "Script" area

import org.apache.jmeter.config.Argument;
import org.apache.jmeter.config.Arguments;

Arguments argz = ctx.getCurrentSampler().getArguments();
for (int i = 0; i < argz.getArgumentCount(); i++) {
    Argument arg = argz.getArgument(i);
    if (arg.getName().equals("email")) {
        vars.put("EMAIL", arg.getValue());
        break;
    }
}

  • 在需要时将生成的值引用为${EMAIL}.
  • Refer generated value as ${EMAIL} where required.
  • 说明:

    • 以上代码将提取email请求参数的值(如果有)并将其存储到EMAIL JMeter变量
    • ctx- JMeterContext 类的简写实例
    • vars = JMeterVariables 类的简写实例
    • ArgumentsArgument-您可以从JMeterContext JavaDoc中弄清楚这一点
    • above code will extract the value of email request parameter (if any) and store it to EMAIL JMeter Variable
    • ctx - shorthand to JMeterContext class instance
    • vars = shorthand to JMeterVariables class instance
    • Arguments and Argument - you can figure that out from JMeterContext JavaDoc

    请参见如何使用BeanShell:JMeter最喜欢的内置组件指南,了解有关JMeter中Beanshell脚本的更多信息.

    See How to use BeanShell: JMeter's favorite built-in component guide for more information on Beanshell scripting in JMeter.

    这篇关于如何从Jmeter中的请求中提取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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